4 ms·
So how extremely could I exploit this? Could I write a program entirely in C, compile it with the D compiler, and use D's unit test framework? That would be i
by beeforpork 5y ago
So how extremely could I exploit this? Could I write a program entirely in C, compile it with the D compiler, and use D's unit test framework? That would be insane (very good insane, obviously).
- WalterBright 5y agoThat is a great question. The point of ImportC is to import the declarations from a C file. But it turns out you can simply give the C file on the command line, and it'll compile it and make an executable: echo hello.c int printf(const char*,...); int main() { printf("hello world\n"); } dmd hello.c ./hello hello world But then there's the question "should D features be allowed in the C code?" This is a very subversive question. Is it really C if that is allowed? Already, the C code allows for Compile Time Function Execution, which comes for free by passing the C code through the D front end. You can see it in action in the test cases in this file: https://github.com/dlang/dmd/pull/12507/files#diff-b94776a026b50e985b5e0bf8c2be0c17fdca9730c5934f47d9ebe6ab9ede35bd https://github.com/dlang/dmd/pull/12507/files#diff-b94776a02... Scroll down a bit and you'll see it executes C functions at compile time. I decided to flirt with heresy and leave this in, because it sure makes adding tests convenient! I'm less sure about adding unittests to the C compiler. Certainly, you can always add the unittests to the D code that is importing the C code. This will probably hold the charges of abomination to a minimum.
- agumonkey 5y agoDo you produce a D ~object from c source which is then processed by dmd ?
- mhh__ 5y agoIt produces a D AST from C syntax.
- crazypython 5y ago> Already, the C code allows for Compile Time Function Execution, which comes for free by passing the C code through the D front end. Oh my good gosh. D and C could be seamless together. This is great. > I decided to flirt with heresy and leave this in I'd love to see more C language extensions in ImportC.