Cannot compile C file using ImportC

rempas rempas at tutanota.com
Wed Nov 10 07:04:47 UTC 2021


On Tuesday, 9 November 2021 at 13:44:04 UTC, Steven Schveighoffer 
wrote:
>
> It seems like it should work. Figuring out the "lines" for 
> things is really difficult in this expanded format, even though 
> I know why it does that. I think importC should possibly allow 
> printing of the actual source line along with the explicit 
> source file/line, because knowing the vagrancies of the 
> preprocessor is not going to be something that's easy to deal 
> with, and you want to see what raw format is being passed to 
> the compiler.
>
> [here](https://gist.github.com/rempas/a1633ba4d3fd4f166277d7ff35cedc63#file-tomld-c-L1439) is where "line 39" of toml.c is.
> [here](https://gist.github.com/rempas/a1633ba4d3fd4f166277d7ff35cedc63#file-tomld-c-L763) is where the definition of `malloc` is.
>
> To me, this looks reasonable. I narrowed it down to the 
> following file, and it builds with gcc and ldc2 on my system. I 
> don't have support for DMD, as this is an Arm system, but on 
> another system, I can confirm that DMD 2.098.0 does not compile 
> this:
>
> ```c
> typedef long unsigned int size_t;
> extern void *malloc (size_t __size)
>      ;
> static void* (*ppmalloc)(size_t) = malloc;
> ```
>
> I used `dmd -c testc.c`, `gcc -c testc.c` and `ldc2 -c testc.c`.
>
> Please file a bug report.
>
> https://issues.dlang.org
>
> -Steve

It works with LDC2 for you? I'm having the latest version (ldc 
1.28.0) downloaded from the 
[release](https://github.com/ldc-developers/ldc/releases/tag/v1.28.0) page for Linux (X86_64) and it doesn't seem to work for me. These 2 errors are not present with LDC2 however, I'm now getting some other errors with LDC2. How was your LDC2 built?

Also it is worth noting that the compiler that is used to 
preprocess the file will result in different error messages when 
trying to use ImportC. For example when using cproc to preprocess 
and then LDC2 to compile, the error message is the following:

```
toml.c(638): Error: assignment cannot be used as a condition, 
perhaps `==` was meant?
toml.c(671): Error: assignment cannot be used as a condition, 
perhaps `==` was meant?
toml.c(1027): Error: assignment cannot be used as a condition, 
perhaps `==` was meant?
toml.c(1140): Error: assignment cannot be used as a condition, 
perhaps `==` was meant?
toml.c(1844): Error: cannot implicitly convert expression 
`*((*tab).arr + cast(long)i * 8L)` of type `const(toml_array_t*)` 
to `toml_array_t*`
toml.c(1855): Error: cannot implicitly convert expression 
`*((*tab).tab + cast(long)i * 8L)` of type `const(toml_table_t*)` 
to `toml_table_t*`
toml.c(1914): Error: cannot implicitly convert expression `0 <= 
idx && (idx < (*arr).nitem) ? (*((*arr).item + cast(long)idx * 
32L)).arr : cast(const(toml_array_t*))0LU` of type 
`const(toml_array_t*)` to `toml_array_t*`
toml.c(1919): Error: cannot implicitly convert expression `0 <= 
idx && (idx < (*arr).nitem) ? (*((*arr).item + cast(long)idx * 
32L)).tab : cast(const(toml_table_t*))0LU` of type 
`const(toml_table_t*)` to `toml_table_t*`
toml.c(2247): Error: assignment cannot be used as a condition, 
perhaps `==` was meant?
toml.c(2305): Error: assignment cannot be used as a condition, 
perhaps `==` was meant?
```

When preprocessing with GCC, both DMD and LDC give the same error 
message and it the same I've got from another time I tried to use 
ImportC and it is 
[here](https://forum.dlang.org/post/sacokknyeqqsayxoudop@forum.dlang.org). Clang has the same behavior as well.

When preprocessing with TCC, again both of them have the same 
error message and it's the following:

```
/usr/include/stdio.h(407): Error: missing comma
/usr/include/stdio.h(407): Error: `=`, `;` or `,` expected
/usr/include/stdio.h(410): Error: missing comma
/usr/include/stdio.h(410): Error: `=`, `;` or `,` expected
/usr/include/stdio.h(412): Error: missing comma
/usr/include/stdio.h(412): Error: `=`, `;` or `,` expected
/usr/include/stdio.h(451): Error: missing comma
/usr/include/stdio.h(451): Error: `=`, `;` or `,` expected
/usr/include/stdio.h(456): Error: missing comma
/usr/include/stdio.h(456): Error: `=`, `;` or `,` expected
/usr/include/stdio.h(459): Error: missing comma
/usr/include/stdio.h(459): Error: `=`, `;` or `,` expected
/usr/include/string.h(410): Error: missing comma
/usr/include/string.h(410): Error: `=`, `;` or `,` expected
```

I haven't tried to preprocess with any other compilers but I 
don't expect anything else to work if these didn't...


More information about the Digitalmars-d-learn mailing list