I was trying to figure out the differences between terminate
, exit
and abort
and the
C++ termination documentation came up in my Google search that compares exit
vs abort
vs atexit
.
I read the first part that compares exit
and abort
and it makes sense.
The difference between exit and abort is that exit allows the C++
runtime termination processing to take place (global object
destructors get called). abort terminates the program immediately. The
abort function bypasses the normal destruction process for initialized
global static objects. It also bypasses any special processing that
was specified using the atexit function.
Then later there was a comparison of return
and exit
with this sample code and corresponding explanation:
// return_statement.cpp
#include <stdlib.h>
struct S
{
int value;
};
int main()
{
S s{ 3 };
exit( 3 );
// or
return 3;
}
The exit and return statements in the preceding example have similar
behavior. Both terminate the program and return a value of 3 to the
operating system. The difference is that exit doesn’t destroy the
automatic variables
, while the return statement does.
Did I misunderstand or is there a mistake because I thought that s
would also be destroyed when exit
is called?