3 ms·
D's ImportC compiler already does this: https://dlang.org/spec/importc.html#ctfe https://dlang.org/spec/importc.html#ctfe It's a natural consequence of using
by WalterBright 5y ago
D's ImportC compiler already does this:
https://dlang.org/spec/importc.html#ctfe https://dlang.org/spec/importc.html#ctfe
It's a natural consequence of using D's semantic analysis for the C compiler.
I thought about removing it, because it's C, but then decided Vot De Heck and left it in. It's quite nice for the test suite for ImportC, too, as an executable doesn't have to be generated to check the semantics.
P.S. No keyword is required to make it work.
P.P.S. ImportC also allows forward references to declarations, another consequence of using D's semantic implementation.
- WalterBright 5y agoHere's ImportC in action: _Static_assert(square(2) == 4, "failed"); int square(int x) { return x * 2; } 1. there is no need for constexpr keyword. Anywhere a constant-expression in the C grammar appears, compile time function execution is involved. 2. `square` is forward referenced, but works fine.
- smartaz42 5y agoHmm, isn't square normally x*x?
- mhh__ 5y agoWalter actually retired years ago and replaced himself with an AI. Every now and again there are bugs, move along.
- WalterGR 5y agoMr. Bright is just using TDD. The ‘square’ function works for 2. Next he’ll generalize it to work for more values. Tests aren’t shown. ;)
- deleted 5y ago[deleted]
- WalterBright 5y agoI tested it, it worked for the one and only test case, therefore it was correct :-)
- aeldidi 5y agoIt's always a pleasure seeing your comments when it comes to language design. I noticed the spec currently says that _Atomic is ignored. Is that a current limitation of the implementation, or is it not planned to ever be implemented? I can see that breaking real C code in surprising ways. Other than that, I can't wait to use ImportC in my own D projects, I have a couple cases where it would simplify builds dramatically.
- WalterBright 5y ago_Atomic is a problem because it doesn't map onto any existing D semantics. D's `shared` is distinctly different. So I decided to move it down on the list of priorities, instead focusing on what I can get done in the shortest time. I'll eventually circle around to it, or someone may beat me to it. It is open source, after all!