following the example in https://dlang.org/spec/importc.html
> ImportC files have one of the extensions .i, or .c. If no extension is given, .i is tried first, then .c.
And
> The Gnu C Preprocessor can be invoked as:
> gcc -E file.c > file.i
When I try to compile the following file (main.c):
```
// main.c
#include <stdio.h>
#include <stdint.h>
typedef struct block_s
{
uint16_t mat_id; // 2
struct {
uint8_t r, g, b, c; // 4
} color;
} block_t;
int main()
{
printf("sizeof(block_t) is %lu\n", sizeof(block_t));
return 0;
}
```
with `gcc -E main.c > main.i && dmd main.i` I get:
```
/usr/include/stdio.h(258): Error: found `__filename` when expecting `,`
/usr/include/stdio.h(258): Error: no type-specifier for parameter
/usr/include/stdio.h(259): Error: found `__modes` when expecting `,`
/usr/include/stdio.h(265): Error: found `__filename` when expecting `,`
/usr/include/stdio.h(265): Error: no type-specifier for parameter
/usr/include/stdio.h(266): Error: found `__modes` when expecting `,`
/usr/include/stdio.h(266): Error: no type-specifier for parameter
/usr/include/stdio.h(267): Error: found `__stream` when expecting `,`
/usr/include/stdio.h(328): Error: found `__stream` when expecting `,`
/usr/include/stdio.h(328): Error: no type-specifier for parameter
/usr/include/stdio.h(328): Error: found `__buf` when expecting `,`
/usr/include/stdio.h(332): Error: found `__stream` when expecting `,`
/usr/include/stdio.h(332): Error: no type-specifier for parameter
/usr/include/stdio.h(332): Error: found `__buf` when expecting `,`
/usr/include/stdio.h(332): Error: no type-specifier for parameter
/usr/include/stdio.h(338): Error: found `__stream` when expecting `,`
/usr/include/stdio.h(338): Error: no type-specifier for parameter
/usr/include/stdio.h(338): Error: found `__buf` when expecting `,`
/usr/include/stdio.h(338): Error: no type-specifier for parameter
/usr/include/stdio.h(350): Error: found `__stream` when expecting `,`
```
This issue happens when compiling pretty much any .i file generated with `gcc -E`. This works fine in `gdc`.
I'm using dmd v2.104.0
Comment #1 by bugzilla — 2023-08-04T01:30:57Z
Hmm, curious, as compiling test.c works without error.
Comment #2 by bugzilla — 2023-08-04T01:44:48Z
Oh, I know what's wrong. The line:
extern FILE *fopen (const char *__restrict __filename,
const char *__restrict __modes) ;
ImportC doesn't recognize the __restrict keyword. (__restrict is not a C11 Standard keyword.). When ImportC runs the preprocessor, it also implicitly #include's the file druntime/src/importc.h, which #define's `__restrict` to nothing.
ImportC is rather heavily reliant on importc.h to adjust the wild extensions in various C compilers to something that ImportC can swill on (the ugly alternative is for ImportC to implement everybody else's extension).
The solution, for your case, is to have gcc use importc.h as well:
gcc -E -include <path-to-importc>importc.h test.c > test.i
where <path-to-importc> is where importc.h is on your system.