View Single Post
Old Nov 8th, 2006, 4:00 PM   #7
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by The Dark View Post
Note that this code will only work from within main. If you made a function using this code, the "name" array will go out of scope while the environment is still using it.
The entry point of your program is the main function. In the main functions, you usually call a number of functions. Does this mean your main function gets out of scope? Well, no. When you call function x, your variables from the main function are still on the stack. How else could you return from function x and continue in your main function?
Your local variables in function main will get unavailable once you return from the main function. And what happens when you quit the main function? Your program is finished, and the variable is no longer used anyway.

I'm not sure how this applies when running multiple threads, it may be OS specific (running another thread while main thread has finished) - another member can probably tell you that. I usually block the main thread when it has ended and other threads have not.
Polyphemus_ is offline   Reply With Quote