I know there is a lot about what is a static variable and about the initialization order, this goes a bit further.
Imagine in 1 CPP, the following lines:
struct A
{
void* a;
size_t b;
};
static bool bMyBoolean = true;
static std::vector<A> myVector;
The guarantee here is that bMyBoolean is initialized before myVector.
They also are both initialized before main() gets called.
However, myVector has a valid value and memory address, but gets initialized during _initterm while bMyboolean is initialized earlier and doesn't need an initialize call during initterm.
This is due to it being a native type it seems, but I can't find any references or info about this behavior.
A bit of context: when I overload malloc for example, and a constructor is called for a userdefined type, it will go into malloc, but some of your static data here is not ready yet (this is expected since static variables between translation units is not guaranteed) but it means I can access and alter it safely, and then it gets re-initialized.
This leads me to the next question, where does this memory live then?
Does it get in-place reconstructed?
Since a malloc call is being made, it then gets initialized. Does it mean the native variables live in a static heap that is allocated at boot of the program, and the user defined types live on the heap?
If that is the case, how can you track your user defined types that are declared static?
boollive in a fixed memory slot, which can be initialized at compile time. Complex objects such as avectorrequire run-time initialization. It's as simple as that.