News for hackers. Stuff that matters.
Re:Adding ANSI C11 C compiler to D so it can import and comp... by WalterBright on Monday May 10, 2021 @05:40AM (#27104284)
That 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-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.

Re:Adding ANSI C11 C compiler to D so it can import and comp... by crazypython on Monday May 10, 2021 @07:46AM (#27104877)
> 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.

Re:Adding ANSI C11 C compiler to D so it can import and comp... by agumonkey on Monday May 10, 2021 @12:17PM (#27107684)
Do you produce a D ~object from c source which is then processed by dmd ?
Re:Adding ANSI C11 C compiler to D so it can import and comp... by mhh__ on Monday May 10, 2021 @12:54PM (#27108104)
It produces a D AST from C syntax.