On Friday, 19 July 2013 at 15:39:36 UTC, Tove wrote:
On Friday, 19 July 2013 at 13:38:12 UTC, Chad Joan wrote:

Even with a conservative target like C89-only, there are still an incredibly large number of extremely useful D features (OOP, templates, scope(exit), CTFE, mixins, ranges, op-overloading, etc) that DO come for free.

I love the idea behind xdc, but I would go with C99 instead, even MS as the last vendor(?), with VS2013 now finally committed to supporting C99, variable length arrays alone would make it worth it.

I am, in fact, totally willing to make --emit=C99 do cool things once I discover what those cool things are. Otherwise it will probably emit code that is both C89 and C99 compliant.

I feel that most of the D features that can be implemented with a C99 compiler can be implemented with C89 as well, and C89 might give more reach into esoteric targets like microcontrollers or legacy systems.

Maybe I should ask this: what D features are you afraid of losing due to lowering into C89?

...

I hate to sour whatever cheerful expectations you might have, but, AFAIK, D doesn't have VLAs. Consequently, I don't think xdc would need them. I hear that VLA support is becoming optional in C11 as well, which doesn't bode well for its potential existance in the future, see http://en.wikipedia.org/wiki/Variable-length_array

"Programming languages that support VLAs include [...] C99 (and subsequently in C11 relegated to a conditional feature which implementations aren't required to support; ..."

It is important to note that even if D /did/ have VLAs, then it would be possible to lower them into other constructs:

void foo(int n)
{
        char[n] vla;
        ...
}

-= can be emulated by =-

void foo(int n)
{
        char[] vla = (cast(char*)std.c.stdlib.malloc(n))[0..n];
        scope(exit) std.c.stdlib.free(vla.ptr);
        ...
}

This would be important for emitting to any language without VLAs. It could be used if someone wanted to add VLAs to xdc as an (off-by-default) experimental feature. And of course it should use "new T[n]" with core.memory.GC.free if the array contains pointers, or stdlib is unavailable (ex: Java). I would also expect --emit=C99 to avoid the heap allocation. alloca might be usable with C89 in some cases, but is very dangerous (in my experience).

----

I had a friend of mine who is an expert C programmer poke me about this C89 vs C99 thing as well. It's strange to me because I thought that emitting C89 was actually a strong selling point: you're getting D which is so much more than C99, AND it will reach all of the old C89 compilers.

If there are still things that you (community inclusive) are afraid of missing, then I am pretty willing to do C99 instead and skip C89. I will need to know what they are though, or it won't make a difference anyway (I can't implement what I don't know about!).

HTH.

Reply via email to