ImportC and #include files

jmh530 john.michael.hall at gmail.com
Mon May 8 17:29:38 UTC 2023


On Monday, 8 May 2023 at 15:57:01 UTC, bachmeier wrote:
> On Monday, 8 May 2023 at 15:50:09 UTC, jmh530 wrote:
>> On Monday, 8 May 2023 at 15:34:32 UTC, jmh530 wrote:
>>> [snip]
>>> I was assuming that importC would re-write that to an enum 
>>> that I could use directly in the D file, but the spec says 
>>> that it doesn't support all uses of metaprogramming with 
>>> these. You think that's what I'm running into?
>>
>> Hmm, I'm not sure how much sense that makes since I'm able to 
>> use it in the .c file...
>
> To my knowledge, you're only able to use them in .c files. .d 
> files aren't run through the preprocessor and I don't know of 
> any way to access a C macro from D...but maybe I'm wrong. I've 
> been using core.stdc.

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.

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.


More information about the Digitalmars-d mailing list