std:: quick_exit
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Program support utilities
|
定义于头文件
<cstdlib>
|
||
|
[
[
noreturn
]
]
void
quick_exit
(
int
exit_code
)
noexcept
;
|
(C++11 起) | |
导致程序正常终止而不完全清理资源。
传递给 std::at_quick_exit 的函数会按其注册顺序的逆序被调用。若异常试图从任何函数传播出去,将调用 std::terminate 。在调用完注册函数后,会执行 std::_Exit ( exit_code ) 。
传递给 std::atexit 的函数不会被调用。
目录 |
参数
| exit_code | - | 程序的退出状态 |
返回值
(无)
示例
运行此代码
#include <cstdlib> #include <iostream> template<int N> void quick_exit_handler() { std::cout << "quick_exit handler #" << N << std::endl; // flush is intended } void at_exit_handler() { std::cout << "at_exit handler\n"; } int main() { if (std::at_quick_exit(quick_exit_handler<1>) || std::at_quick_exit(quick_exit_handler<2>)) { std::cerr << "Registration failed\n"; return EXIT_FAILURE; } std::atexit(at_exit_handler); // the handler will not be called struct R { ~R() { std::cout << "destructor\n"; } } resource; /*...*/ std::quick_exit(EXIT_SUCCESS); std::cout << "This statement is unreachable...\n"; }
输出:
quick_exit handler #2 quick_exit handler #1
参见
|
导致程序异常终止(不进行清理操作)
(function) |
|
|
导致程序正常终止并执行清理操作
(function) |
|
|
注册在调用
std::exit()
时要执行的函数
(function) |
|
|
(C++11)
|
注册在调用
std::quick_exit
时要执行的函数
(function) |
|
C documentation
for
quick_exit
|
|