noob in c macro preprocessor hell converting gsl library header files

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 6 05:59:44 PST 2016


On Wednesday, 6 January 2016 at 13:36:03 UTC, data pulverizer 
wrote:
> I have been converting C numeric libraries and depositing them 
> here: https://github.com/dataPulverizer. So far I have glpk and 
> nlopt converted on a like for like c function basics. I am now 
> stuck on the gsl library, primarily because of the preprocessor 
> c code which I am very new to. The following few are 
> particularly baffling to me:
>
> #define INLINE_FUN extern inline // used in gsl_pow_int.h: 
> INLINE_FUN double gsl_pow_2(const double x) { return x*x;   }
>
> Could I just ignore the INLINE_FUN and use alias for function 
> pointer declaration? For example ...
>
> alias gsl_pow_2 = double gsl_pow_2(const(double) x);

Yes, you should be able to ignore INLINE_FUN

double gsl_pow_2(const double x);

is the correct declaration.

> #define INLINE_DECL // used in interpolation/gsl_interp.h: 
> INLINE_DECL size_t gsl_interp_bsearch(const double x_array[], 
> double x, size_t index_lo, size_t index_hi);
>
> I would guess the same as for INLINE_FUN?

yes

> #define GSL_VAR extern // used in rng/gsl_rng.h:GSL_VAR const 
> gsl_rng_type *gsl_rng_borosh13;
>
> perhaps GSL_VAR can be ignored and I could use:
>
> gsl_rng_borosh13 const(gsl_rng_type)*;

It should be

extern gsl_rng_type* gsl_rng_borosh13;

> I have been using these kind of fixes and have not been able to 
> get the rng module to recognise the ported functions, meaning 
> that something has been lost in translation.
>
> I am currently getting the following error:
>
> $ gsl_rng_print_state
>
> rng_example.o: In function `_Dmain':
> rng_example.d:(.text._Dmain+0x13): undefined reference to 
> `gsl_rng_print_state'
> collect2: error: ld returned 1 exit status
>
> I can't seem to call any of the functions but the types are 
> recognized.
>
> Thanks in advance

I think you might have some confusion between function 
declarations:

T myFunction(Q myArg);

function pointer type declarations:

alias MyFunctionPointerType = T function(Q myArg);

and function pointer declarations:

MyFunctionPointerType myFunctionPointer;


More information about the Digitalmars-d-learn mailing list