Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actuallride

Posted 08 October 2012 - 02:47 PM

Yes it would try to destruct twice and have odd side effects - hopefully crashing your program, but possibly not crashing but wrecking other parts of your progam in unpredictable ways.

But unfortunately, exit() apparently doesn't unwind the stack like I initially thought.


if it exit() doesn't unwind the stack, why would the destructor be called?
http://stackoverflow...om-being-called

exit() is more complicated than I thought... This is what it says in the standard...
Calling the function void exit(int); declared in <cstdlib> (18.3) terminates the program without leaving the current block and hence without destroying any objects with automatic storage duration (12.4). If exit is called to end a program during the destruction of an object with static storage duration, the program has undefined behavior.

I have no idea what it means by
If exit is called to end a program during the destruction of an object with static storage duration, the program has undefined behavior.
(say I called exit(0). Then my program has undefined behavior while returning 0. )

EDIT:
It turns out that return 0 is more favorable than exit(0)
http://stackoverflow.com/questions/461449/return-statement-vs-exit-in-main

#3lride

Posted 08 October 2012 - 02:33 PM

Yes it would try to destruct twice and have odd side effects - hopefully crashing your program, but possibly not crashing but wrecking other parts of your progam in unpredictable ways.

But unfortunately, exit() apparently doesn't unwind the stack like I initially thought.


if it exit() doesn't unwind the stack, why would the destructor be called?
http://stackoverflow...om-being-called

exit() is more complicated than I thought... This is what it says in the standard...
Calling the function void exit(int); declared in <cstdlib> (18.3) terminates the program without leaving the current block and hence without destroying any objects with automatic storage duration (12.4). If exit is called to end a program during the destruction of an object with static storage duration, the program has undefined behavior.

I have no idea what it means by
If exit is called to end a program during the destruction of an object with static storage duration, the program has undefined behavior.
(say I called exit(0). Then my program has undefined behavior while returning 0. )

#2lride

Posted 08 October 2012 - 02:28 PM

Yes it would try to destruct twice and have odd side effects - hopefully crashing your program, but possibly not crashing but wrecking other parts of your progam in unpredictable ways.

But unfortunately, exit() apparently doesn't unwind the stack like I initially thought.


if it exit() doesn't unwind the stack, why would the destructor be called?
http://stackoverflow...om-being-called

exit() is more complicated than I thought... This is what it says in the standard...
Calling the function void exit(int); declared in <cstdlib> (18.3) terminates the program without leaving the current block and hence without destroying any objects with automatic storage duration (12.4). If exit is called to end a program during the destruction of an object with static storage duration, the program has undefined behavior.

I have no idea what it means by
If exit is called to end a program during the destruction of an object with static storage duration, the program has undefined behavior.

#1lride

Posted 08 October 2012 - 02:25 PM

Yes it would try to destruct twice and have odd side effects - hopefully crashing your program, but possibly not crashing but wrecking other parts of your progam in unpredictable ways.

But unfortunately, exit() apparently doesn't unwind the stack like I initially thought.


if it exit() doesn't unwind the stack, why would the destructor be called?
http://stackoverflow.com/questions/2668075/will-exit-or-an-exception-prevent-an-end-of-scope-destructor-from-being-called

PARTNERS