View mode: basic / threaded / horizontal-split · Log in · Help
May 30, 2009
D compiler as a C++ preprocessor
Hello,

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?

Thanks, Dmitry
May 30, 2009
Re: D compiler as a C++ preprocessor
> 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?

No.
May 30, 2009
Re: D compiler as a C++ preprocessor
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.

Bye,
bearophile
May 30, 2009
Re: D compiler as a C++ preprocessor
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.
June 28, 2009
Re: D compiler as a C++ preprocessor
Sat, 30 May 2009 04:16:09 -0400, Dmitry Sychov wrote:

> 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? 

I'm sure translation from D into C were discussed before, not even once,
as a means of diversifying the list of supported platforms.  The culprit
was exception handling.  The conversion to C++ were discussed too IIRC,
but not as enthusiastically for some reason.  I cannot think of any real
blockers for such a `preprocessor'.  Maybe forward references, but the
current D compiler has problems with them as well.
Top | Discussion index | About this forum | D home