Mainstream D Programming

Peter C. Chapin pchapin at sover.net
Sun Oct 14 04:34:16 PDT 2007


Janice Caron wrote:

> I'm not completely sure it could be done at all.

If D can be translated to assembly language, it can be translated to
C++. How readable the result might be is another question. However,
given that C++ is a significantly higher level language than assembly, I
suspect a D to C++ compiler could output C++ that is at least somewhat
approachable.

In any case, reading the C++ coming out of such a compiler is probably
not necessary. The OP is interested in using D in environments where
only a C++ compiler is available. If the D to C++ conversion was well
done, the resulting C++ code should compile cleanly and never need
editing or even reading.

Systems like this have been created for other languages. The original
C++ compiler produced output in C. There is also an Ada compiler that
outputs C. In both of these cases the reasons for their creation was the
same: to allow (C++, Ada) to be used in an environment where no native
compiler exists.

Keep in mind that these translation tools are full compilers. The
conversions are not accomplished with simple macro substitutions or
anything similar. I suspect, for the reasons you mentioned, that a D to
C++ compiler would have to basically be a full D front end with a "code"
generator that output C++. Creating such a compiler would be a
significant amount of work, although as the OP suggests it would no
doubt help greatly in the spread of D (just as the original C++ "cfront"
compiler helped the spread of C++).

Actually it probably would be even better to compile D into C if one was
going to do something like this. C compilers are even more common than
C++ compilers.

Peter



More information about the Digitalmars-d mailing list