local Static C++

Hi Experts,

As all statics are getting created before the main() execution, i wanted to particular about static data that is local to function. As per the text i have read it says it gets created first time when line containing static data is executed, ..

Does this mean that storage for static data inside function is allocated before main() execution but is initialized only when the statement inside the function is executed?
No. Instances of classes within a function, such as main, are initialised before main is run.
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.14 faq presents one method, to delay the initialisation of static data and places the data in function to do so. As per this faq, data is initialised only when this function is called...
pparesh is correct. Local static variables are not initialized before main, they're initialized on first use.

As for when the storage is allocated, I have no idea. I wonder if that behavior is even standardized or if it's the compiler's discresion.
Storage is allocated prior to main.
Topic archived. No new replies allowed.