Re: [9fans] A compiler bug
On Aug 1, 2018, at 4:35 PM, Charles Forsyth wrote: > even so, the format and intention of the example seems practical (with the > correct cast to uintptr) and "An implementation may accept other forms of > constant expressions". > it should be fairly easy to add as an extension with consistent handling > across ?c. Both gcc and clang handle this case. This example was derived from ObjectIcon (it works on plan9/x86 & unix systems but not on plan9/arm). I am not familiar with the C compiler sources but will take a look. Thanks for your response.
[9fans] A compiler bug
Consider: % cat x.c #include uintptr foo[3]; uintptr bar=[2]; % 8c -c x.c # this works. % 5c -c x.c # this fails x.c:3 initializer is not a constant: bar If I change the last line to uintptr* bar=[2]; Both compilers compile it fine. But if I change the last line to uintptr bar=(uintptr)[2]; both compilers fail. Note that the last two examples are type correct. uintptr is the same size as int* so there should be no runtime cost and we already know from the second example that [2] is a link time constant. Similar code to the last two examples compiles on gcc/clang. This seems like a compiler bug.