this is my code. I wrote this part outside my main
typedef struct { int x; } foo;
const int bar = 2;
foo myFoo = { (int) bar };
However this returns:
common.c:6: error: initializer element is not constant
common.c:7: error: (near initialization for ‘myFoo.x’)
If I copy and paste the code into the main it will work.
Can someone give me an explanation please?
you can do using
enumlike:or
using
#define bar 2likeBut both are known at compilation time: why not?