I never given too much thought to the problem of initialization of a in-function static variable in C/C++ (mostly C++ though). I just blindly assumed that the static variable works identically to a global variable, but is directly accessible (using language provided means) only in the block of code (and its child blocks) in which it was declared/defined. This is partly true of course - the big difference is that the global variable is initialized either at compilation time (constant) or before the entry point, and the static variable is initialized either at compilation time (constant) or at the first entry to the block of code where it's declared/defined. The interesting parts here are "how does the variable know if it has been initialized" and "what about concurrent multi-threading?" (the latter has some minor stability/security consequences). Let's take a look at GCC and Microsoft Visual C++ and how do they handle these issues...

Post dostępny jedynie po angielskiej stronie lustra.

Add a comment:

Nick:
URL (optional):
Math captcha: 9 ∗ 1 + 3 =