命名空间
变体
操作

std::quick_exit

来自 cppreference.cn
< cpp‎ | utility‎ | program
 
 
 
 
定义于头文件 <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

[编辑] 参见

导致程序异常终止(不清理)
(函数) [编辑]
导致程序正常终止并清理
(函数) [编辑]
注册一个在 std::exit() 调用时被调用的函数
(函数) [编辑]
注册一个在 std::quick_exit 调用时被调用的函数
(函数) [编辑]
C 文档 关于 quick_exit 的内容