Is it illegal / dangerous?
int* static_nonew()
{
static int n = 5;
return &n;
}
The compiler has no problems with it, but is the pointer location safe from being overwritten when someone else needs memory?
EDIT: A little more explanation why I asked this question. Note. I am programming in C ++, I just marked it as C, because it seems to be more of a C question than C ++.
I have a class that should return a static map. I want this card to be initialized once during the whole program, as there seems to be no need to do this several times. For this reason, I will have something like this:
static std::map<std::string, Transition*> transitions;
static Transition trans1(transitions, ...);
static Transition trans2(transitions, ...);
return &transitions;
. , , . , , , "". , , , .