Hi there.
Could anyone please explain to me why, when I compile the following code with GCC I got an error?
Code:
Code:
#include <stdio.h>
const int CONSTANT_1 = 3;
const int CONSTANT_2 = CONSTANT_1 + 2;
int main (void) {
printf("Constant 2 is: %d\n", CONSTANT_2);
return 0;
}
The error I got is:
"test_const.c:4:1: error: initializer element is not constant
const int CONSTANT_2 = CONSTANT_1 + 2;"
When I run it in CLANG it works fine.
It also work (in GCC and CLANG) when in declare the constants inside the main function.
Thanks in advance.