Simple c header => Dlang constants using mixins in compile time

Igor Shirkalin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 17 04:20:53 PDT 2017


On Saturday, 17 June 2017 at 11:10:47 UTC, Igor wrote:
> On Saturday, 17 June 2017 at 10:56:52 UTC, Igor Shirkalin wrote:
>> Hello!
>>
>> I have a simple C header file that looks like:
>> #define Name1 101
>> #define Name2 122
>> ....
>> #define NameN 157
>>
>> It comes from resource compiler and I need all these constants 
>> to be available in my Dlang program in compile time. It seems 
>> to me it is possible. I know I can simply write external 
>> program (in python, for example) that does it, but it means I 
>> should constantly run it after every change before D 
>> compilation.
>>
>> Please, can anyone help to direct me how to realize it?
>> Thank you in advance!
>>
>> Igor Shirkalin
>
> Maybe I am not quite understanding what you are asking but 
> can't you just use:
>
> enum Name1 = 101;
> enum Name2 = 122;
> ...

No, I need the original header file to be used in other 
applications (say, resource compiler). Therefore this file is 
primary. I think some pretty short code can be written in D that 
use such a file to generate constants (enum Name1 = 101) in 
compile time.


More information about the Digitalmars-d-learn mailing list