I have seen it written that:
The static initializer is executed before the first invocation of the containing function; the initializer expression must be a compile-time constant.
Consider this:
void func(){
static float tr=((float) rand() / (RAND_MAX));
}
tr
depends on a runtime function, rand()
. I don't think the value of rand()
is known at compile time, is it? Yet this compiles fine in C++ and a lot of answers/literature indicate that C behavior is the same as C++ in this regard.