On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote:
Hi friends,
Is there a way to "compile" d code to C, similar to what nim
does?
That would be cool for greater portability.
Nim is able to, because Nim doesn't really compile. The Nim
compiler just translates Nim code to C code and then compiles the
C code.
It's much harder to do properly in D, because D doesn't use C as
a backend, but compiles directly to native.
I'd guess the code generation you'd get from doing so with D
would be absolute horrific to read, because you'll get rid of
CTFE, templates, proper class structure, globals properly stored,
since everything in D is TLS and C doesn't then you'll see weird
constructs everywhere.
If you ask me, it's probably not something you want to do and
there really isn't a reason to do it with D either. D has an
almost 100% compatibility with C already.