Discussion:
What is 'XIP__XIP_IMPEXP' here?
(too old to reply)
fl
2017-05-11 01:48:35 UTC
Permalink
Raw Message
Hi,

I feel it is puzzling of the below code snippets:



in a common.h file:

//Determine shared library import attributes
#ifndef XIP__XIP_IMPEXP
#if defined(NT) || defined(NT64)
#define XIP__XIP_IMPEXP __declspec(dllimport)
#elif defined(LIN) || defined(LIN64)
#define XIP__XIP_IMPEXP
#else
#define XIP__XIP_IMPEXP
#endif
#endif


another .h file:


#include "common.h"

//Helpers for creating arrays
XIP__XIP_IMPEXP xip_array_uint* xip_div_gen_v5_1_xip_array_uint_alloc(size_t num_samples);

Does below mean
#define XIP__XIP_IMPEXP

===>

XIP__XIP_IMPEXP==1




Then, What is below 'XIP__XIP_IMPEXP'?

XIP__XIP_IMPEXP xip_array_uint* xip_div_gen_v5_1_xip_array_uint_alloc(size_t num_samples);


Thanks,
Barry Schwarz
2017-05-11 04:32:07 UTC
Permalink
Raw Message
Post by fl
Hi,
//Determine shared library import attributes
#ifndef XIP__XIP_IMPEXP
#if defined(NT) || defined(NT64)
#define XIP__XIP_IMPEXP __declspec(dllimport)
If this line is reached (both the first condition and either of the
last two conditions are true), then every later occurrence of
"XIP__XIP_IMPEXP" in the translation unit will be replaced with
"__declspec(dllimport)".
Post by fl
#elif defined(LIN) || defined(LIN64)
#define XIP__XIP_IMPEXP
#else
#define XIP__XIP_IMPEXP
If either of these two lines are reached, then every occurrence of
"XIP__XIP_IMPEXP" will be replaced with "".
Post by fl
#endif
#endif
#include "common.h"
//Helpers for creating arrays
XIP__XIP_IMPEXP xip_array_uint* xip_div_gen_v5_1_xip_array_uint_alloc(size_t num_samples);
Depending on which of the three defines above was actually processed,
this line will be changed by the preprocessor to either
__declspec(dllimport) xip_array_uint*
xip_div_gen_v5_1_xip_array_uint_alloc(size_t num_samples);
or
xip_array_uint* xip_div_gen_v5_1_xip_array_uint_alloc(size_t
num_samples);
Post by fl
Does below mean
#define XIP__XIP_IMPEXP
===>
XIP__XIP_IMPEXP==1
Not at all. It means that the macro is defined but expands to text of
zero length (similar to the empty string but without the terminating
/0).
Post by fl
Then, What is below 'XIP__XIP_IMPEXP'?
XIP__XIP_IMPEXP xip_array_uint* xip_div_gen_v5_1_xip_array_uint_alloc(size_t num_samples);
Answered above.
--
Remove del for email
bartc
2017-05-11 10:50:20 UTC
Permalink
Raw Message
Post by fl
//Determine shared library import attributes
#ifndef XIP__XIP_IMPEXP
#if defined(NT) || defined(NT64)
#define XIP__XIP_IMPEXP __declspec(dllimport)
#elif defined(LIN) || defined(LIN64)
#define XIP__XIP_IMPEXP
#else
#define XIP__XIP_IMPEXP
#endif
#endif
#include "common.h"
//Helpers for creating arrays
XIP__XIP_IMPEXP xip_array_uint* xip_div_gen_v5_1_xip_array_uint_alloc(size_t num_samples);
Lovely example!

Yet, this is not even the worst such I've come across, as at least it's
clear that it's a function declaration of some kind. If the parts are
shorted and renamed just to be able to 'grok' the form:

A B * C (int samples);

Because it is a function declaration, then presumably C is the name, and
B is the type; A will be some attribute in the form of a macro. Then it
can be rewritten as:

M T* F(int samples);

Looking at the definition of M, then it will either be nothing, or
'__declspec(dllimport)', needed for shared library imports on some systems.

So:

M is the attribute, either nothing, or __declspec(dllimport)
T* is the return type, a pointer to xip_array_uint
F is the name of the function, the snappy-sounding:
xip_div_gen_v5_1_xip_array_uint_alloc
Post by fl
I see this typedef, which has '[1]' while the below declaration
without it.
Post by fl
What use is '[1]'?
Thanks
-----------------
typedef __mpz_struct mpz_t[1];
mpz_t s_divisor;
This is not so bad as the above, but it shows when happens when a coding
style fixates on some prefix - xip above, mpz here, and uses it
everywhere, even twice within the same identifier above, making it hard
to distinguish one name from another.

This is saying:

typedef T U[1]

This declares U as a synonym for T[1]. So U is an array type (rather a
short array). Then:

U x;

declares x as a variable of type U. In other words, as a one element
array array of type T. (But there may be some subtle differences in
behaviour which you may discover. For example, if U x is a parameter
declaration, then x is actually of type T*).

Anyway, your example declares s_divisor as a one-element array of
__mpz_struct. You'll have to look elsewhere for what __mpz_struct is.
--
bartc
Loading...