I want to kill my c++ program and terminate immediately without activating destructors of any kind, especially static and global variables, but I want to exit with status 0 - abort()
will not work for me.
Does anyone have a solution? Thanks
I want to kill my c++ program and terminate immediately without activating destructors of any kind, especially static and global variables, but I want to exit with status 0 - abort()
will not work for me.
Does anyone have a solution? Thanks
Maybe _exit(0);
is what you're looking for?
Here is the man page to read up about it.
From C++11 n3290 - § 18.5:
[[noreturn]] void _Exit(int status) noexcept;
The program is terminated without executing destructors for objects of automatic, thread, or static storage duration and without calling functions passed to atexit()
This is actually defined in C99 though so in practice works on a large number of pre-C++11 implementations.
Use:
#include <cstdlib>
#include <iostream>
struct test {
~test() {
std::cout << "Goodbye world" << std::endl;
}
};
int main() {
test t;
_Exit(0);
}
How about _Exit(0)
from stdlib.h
. (Demo: http://ideone.com/ecCgC)