C header file importer using -J

BCS anon at anon.com
Sun Nov 14 07:58:44 PST 2010


Hello Peter,

> Would it be theoretically possible to use string mixins, CTFE, and
> import expressions (using the -J switch) to write a function
> cHeaderInclude such that it may be used like:
> 
> mixin( cHeaderInclude( import( "someheader.h" ) ) );
> 
> I'm imagining that the cHeaderInclude function would parse the C code
> from the header, convert it to D declarations at compile time, and
> then returns those declarations to be mixed in, just like an #include
> would do.
> 
> Preprocessor defines could be handled with extra parameters:
> "SOME_DEF=1, ANOTHER_DEF=foo" etc.
> 
> Am I missing something that would make this impossible?
> 

That should be possible but would be highly complex. In effect you would 
 need to implement a large chunk of a compiler. Given that there is already 
a tool to do that offline (http://www.digitalmars.com/d/2.0/htod.html) it 
would, IMHO, be inadvisable.




More information about the Digitalmars-d mailing list