In the C language, in order to initialize a static local variable to a value unknown during compilation, I would normally do something like this (for example):
void func() { static int var = INVALID_VALUE; if (var == INVALID_VALUE) var = some_other_func(); ... } In the C++ language, I can simply do:
void func() { static int i = some_other_func(); ... } The only way (that I can think of) for a C++ compiler to resolve it properly, is by replacing this code with a mechanism similar to the C example above.
But how would the compiler determine a "proper" invalid value? Or is there another way which I haven't taken into consideration?
Thanks
Clarification:
INVALID_VALUE is a value which function some_other_func never returns.
It is used in order to ensure that this function is never invoked more than once.
INVALID_VALUErepresent? And what's the point of it?some_other_funcnever returns to check ifvarhas been assigned a return value of that function.some_other_funcwill never return (for example, if it was a pointer, then I would normally useNULL).