Archived

This topic is now archived and is closed to further replies.

Endemoniada

Variables Declared in Functions

Recommended Posts

Hi guys, I never fully understood this so maybe someone can explain it to me. Here is an example: BOOL MyFunction() { BOOL bSuccess=InitSomething(); // ok, if that fails no need to go on if(bSuccess == FALSE) return FALSE; // now I do some stuff CMyClass myClass; // ... do lots of stuff double x; x=666.0; return TRUE } Alright, say the constructor for myClass does lots of stuff, like memory allocation; if the function returns FALSE at the top will the constructor still be called ? Won''t the double x I declared be allocated on the heap (I think it''s the heap) even if it returns FALSE at the top ? I''m using VC++ 6.0. Thanks.

Share this post


Link to post
Share on other sites
As far as I know the constructor won't be called, since you leave the function before this would be done...

edit: oh yeah and the double x will be allocated on the stack, not the heap.

Indeterminatus

--si tacuisses, philosophus mansisses--

[edited by - Indeterminatus on April 22, 2004 2:50:10 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Nothing gets executed beneath that return statement. Also, myClass and double x will get allocated in the stack, not heap. Things are put into the heap when you use "new".

Share this post


Link to post
Share on other sites