digitalmars.D.learn - Should importC fail on invalid C code?
After reading Walter's remark "ImportC sees those macro
definitions and transforms them into manifest constant
declarations" in
Issue 23622 - ImportC #defines conflict with declarations
I wondered how it was implemented:
`myccode.c`
```
int getx ()
{
return X;
#define X 1
}
```
`imc.d`
```
unittest {
import myccode;
assert (false, "Should img.c really compile?");
}
```
```
dmd -O -checkaction=context -unittest -main myccode.c -run imc.d
imc.d(3): [unittest] Should img.c really compile?
1/1 modules FAILED unittests
```
Jan 13 2023
On Friday, 13 January 2023 at 12:50:44 UTC, kdevel wrote:Should importC fail on invalid C code?In general, no. The purpose is to build / interface with existing C code, not to develop new C code with it. ImportC also has its own extensions by borrowing D features such as __import, CTFE, and forward references. A strict C compiler would reject those.
Jan 13 2023








Dennis <dkorpel gmail.com>