Fixing C's Biggest Mistake
Iain Buclaw
ibuclaw at gdcproject.org
Fri Dec 23 12:34:57 UTC 2022
On Thursday, 22 December 2022 at 21:18:04 UTC, Walter Bright
wrote:
> On 12/22/2022 2:21 AM, Iain Buclaw wrote:
>> Which no one will ever use. :-)
>
> They were very useful for the ImportC test suite.
It's still a DMD folly. GDC has been able to compile C files
since day 0 (19 years ago?) as it delegates foreign sources to
the other compilers it was built with - the reverse also works,
GCC can compile D sources because it uses the same mechanism. So
you could say that C and C++ have been capable of compiling D
sources since 2019. ;-)
```
$ gccgo -fno-druntime compiler/test/runnable/bcraii.d -o go-bcraii
$ ./go-bcraii
S.this()
S.~this()
inside
```
None of these tests where dmd pretends to be a C compiler even
work outside of dmd.
```
$ gdc compiler/test/compilable/cimport.c
compiler/test/compilable/cimport.c:3:1: error: unknown type name
‘__import’
3 | __import core.stdc.stdarg;
| ^~~~~~~~
compiler/test/compilable/cimport.c:3:14: error: expected ‘=’,
‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
3 | __import core.stdc.stdarg;
| ^
compiler/test/compilable/cimport.c:4:1: error: unknown type name
‘__import’
4 | __import imports.impcimport;
| ^~~~~~~~
compiler/test/compilable/cimport.c:4:17: error: expected ‘=’,
‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
4 | __import imports.impcimport;
| ^
compiler/test/compilable/cimport.c: In function ‘foo’:
compiler/test/compilable/cimport.c:8:5: error: unknown type name
‘va_list’
8 | va_list x;
| ^~~~~~~
compiler/test/compilable/cimport.c:1:1: note: ‘va_list’ is
defined in header ‘<stdarg.h>’; did you forget to ‘#include
<stdarg.h>’?
+++ |+#include <stdarg.h>
1 | // https://issues.dlang.org/show_bug.cgi?id=22666
compiler/test/compilable/cimport.c:9:16: error: ‘A’ undeclared
(first use in this function)
9 | return 1 + A;
| ^
compiler/test/compilable/cimport.c:9:16: note: each undeclared
identifier is reported only once for each function it appears in
```
DMD becoming a C compiler is a side-effect of importC, but just
because you can doesn't mean you should.
More information about the Digitalmars-d
mailing list