名稱空間
變體
操作

std::quick_exit

來自 cppreference.com
< 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