News for hackers. Stuff that matters.
Re:C Isn't a Programming Language Anymore by WalterBright on Monday November 07, 2022 @04:52PM (#33513076)
> You can’t actually write a C parser

Actually, you can. I added one to the D compiler, and dubbed it ImportC. With ImportC, in your D code you can write:

    import stdio;
and if there's a stdio.h file, the D compiler will read the .h file, parse it, and present the ABI to it in a D-ish manner to your D code. Here it is:

https://github.com/dlang/dmd/blob/master/compiler/src/dmd/cp...

It's so darned useful I expect other languages will do it, too. People were skeptical at first, but it's a solid gold productivity enhancer.

Re:C Isn't a Programming Language Anymore by Hemospectrum on Monday November 07, 2022 @06:11PM (#33513848)
1. Doesn't the D compiler contain an entire C compiler? Half the point of that section was to say that any C parser is halfway to being a fully functional compiler. That's arguably an exaggeration, but I fail to see how D serves as a counterexample.

2. How does the D compiler handle GCC- and Clang-specific extensions to C?

Re:C Isn't a Programming Language Anymore by WalterBright on Monday November 07, 2022 @08:25PM (#33514908)
1. Yes, it does, but only the cparse.d file is for C. The rest of the "C" compiler hijacks the D semantic routines, code generator, and optimizer. There's also some custom work to turn #define's into simple declarations. If you just want to parse C, yes, you can just use cparse.d.

It's important to note that C cannot be fully parsed without keeping a symbol table, and cparse.d handles that, too.

2. C extensions will always be a problem. ImportC supports the most widely used ones. (Most C extensions are rarely used and can be ignored.)

Re:C Isn't a Programming Language Anymore by pencilguin on Monday November 07, 2022 @11:36PM (#33515902)
C++ did this, what, 40 years ago? Then V, Zig, now D. I agree, in ten years most compilers and even interpreters will do it.
Re:C Isn't a Programming Language Anymore by WalterBright on Monday November 07, 2022 @11:42PM (#33515929)
C++ did it the other way around. It added C++ to a C compiler.
Re:C Isn't a Programming Language Anymore by pencilguin on Tuesday November 08, 2022 @01:08AM (#33516361)
But it didn't. In very few cases was a C compiler extended to compile C++. Instead, a C++ compiler just has to know how to compile C, and to link with C objects compiled separately.
Re:C Isn't a Programming Language Anymore by WalterBright on Tuesday November 08, 2022 @12:36PM (#33521732)
But it did. I wrote the first native C++ compiler, by extending the Zortech C compiler.
Re:C Isn't a Programming Language Anymore by pencilguin on Tuesday November 08, 2022 @06:35PM (#33525736)
That does not contradict my statement.
Re:C Isn't a Programming Language Anymore by Imperatorn on Tuesday November 08, 2022 @01:03PM (#33522079)
That's a less correct description than what Walter gave