3 ms·
Although many compilers allow const int X = 33; enum { Y = X };
by uecker 5y ago
Although many compilers allow
const int X = 33;
enum { Y = X };
- qalmakka 5y agoThat's a GNU extension that everyone relies so much on it's basically akin to a standard. You get a warning from Clang (or an error from GCC) if you ask for a more "standard" interpretation of the source: $ clang -o cs cs.c -Wall -std=c11 -pedantic cs.c:6:6: warning: expression is not an integer constant expression; folding it to a constant is a GNU extension [-Wgnu-folding-constant] A = X, $ gcc -o cs cs.c -Wall -std=c11 cs.c:6:9: error: enumerator value for ‘A’ is not an integer constant 6 | A = X, | ^ In general, that's illegal ISO C and should always be rejected, but as you see that's not usually the case.