Support for C header files in D

John Reimer John_member at pathlink.com
Mon Mar 20 12:05:58 PST 2006


In article <dvmit2$34d$1 at digitaldaemon.com>, Don Clugston says...

<snip>

>Writing a C pre-processor does not seem too difficult (is that correct, 
>Walter?) Maybe there's even source code for one lying around.
>(boost.wave is available, but it seems unnecessarily complicated).
>

There are good preprocessors out there. Beyond using the ones integrated in dmc
and gcc, there is mcpp ( http://www.m17n.org/mcpp/index_eng.html ).

I like mcpp.  I've used it for C -> D conversion projects successfully.  The
preprocessor junk is by far the biggest challenge in the conversion process and
using mcpp seems to make short work of the procedure as long as the correct
command line definitions are declared. 

I used mcpp as one of the steps in converting the large complicated freetype
header array (which uses macros so extensively that it makes the source hard to
follow) into consumable text for my python scripts.  These custom scripts then
output the appropriate D source in a format compatible with my dynamic loader
engine.  I ended up touching up the resulting D source with some manual changes,
but the whole conversion could probably have been automated completely.

I know Tom S., aka h3r3tic, has also done similar procedures with C -> D header
conversion, although I think he has used the integrated compiler preprocessor
for the job.

mcpp is opensource, and I imagine it could be integrated into a bigger D -> C
header project without too much difficulty.

-JJR





More information about the Digitalmars-d mailing list