ImportC and #include files

bachmeier no at spam.net
Mon May 8 17:54:45 UTC 2023


On Monday, 8 May 2023 at 17:29:38 UTC, jmh530 wrote:

> If you have a simple #define in a .c file, you can access it 
> from a .d file. I tried the importC spec example with `#define 
> COLOR 0x123456` getting re-written to `enum COLOR = 0x123456;` 
> and it worked.

That's useful to know. I was not aware.

> The HUGE_VAL macro is a little more complicated. It relies on 
> #if and it calls some `__builtin_huge_val`. However, if I have 
> `static double LARGE_VAL = HUGE_VAL` in the .c file, I was able 
> to access LARGE_VAL in the .d file as expected. So the 
> preprocessor is able to run, but maybe it's not creating the 
> enum version due to the other macros going on.

Looks like that's gcc:

https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005fhuge_005fval

Probably requires an addition to importc.h, as has been done for 
several other cases already:

https://github.com/dlang/dmd/blob/master/druntime/src/importc.h#L79


More information about the Digitalmars-d mailing list