www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D compiler as a C++ preprocessor

reply Dmitry Sychov <accelware accelware.com> writes:
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
next sibling parent grauzone <none example.net> writes:
 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
prev sibling next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
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
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
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.
May 30 2009
prev sibling parent Sergey Gromov <snake.scaly gmail.com> writes:
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.
Jun 28 2009