D compiler as a C++ preprocessor

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sat May 30 03:10:35 PDT 2009


bearophile wrote:
> Dmitry Sychov:
>> Can D compiler be used only as a C++ preprocessor, that it to generate  C++ output (platform independent) to be later compiled via the target platform C++ compiler?
> 
> It may be possible to induce LDC to output C code.

With the LLVM C backend linked in it might come close to working. There are some 
issues with this, though.

First of all, the C backend is a bit out of date. LLVM has started turning some 
stuff into large integers (> 64 bits), and last I heard the C backend can't 
handle those properly. (Other backends handle them just fine since pretty much 
only bitwise operations are generated for them, not more tricky stuff like 
multiplication and division)

Second, it still won't be platform independent, which was what Dmitry asked for. 
This is because LLVM doesn't see the code until templates are instantiated, 
mixins are mixed in, static ifs and versions have been evaluated, and so on.



More information about the Digitalmars-d mailing list