ImportC const

Steven Schveighoffer schveiguy at gmail.com
Sat Jul 9 17:07:16 UTC 2022


Brian Callahan has a blog post about ImportC:

https://briancallahan.net/blog/20220704.html

One part identifies a current design choice that breaks C code:

	OK, so I built this file with clang and kept going. There was one more 
file that DMD couldn't compile:

```
dmd -g -O -P=-DEMACS -P=-DVI -ofexpr.o -c expr.c
expr.c(204): Error: cannot modify `const` expression `(*es).tok`
expr.c(205): Error: cannot modify `const` expression `(*es).val`
```
	I wonder if this is a bug in ImportC. No other C compiler we've tried 
fails on this code.

The answer is, no it's not a bug, it's by design: 
https://dlang.org/spec/importc.html#const

Is there any benefit to breaking any usage of const in C when trying to 
compile C code?

-Steve


More information about the Digitalmars-d mailing list