命名空间
变体
操作

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