名稱空間
變體
操作

std::_Exit

來自 cppreference.com
< cpp‎ | 實用工具‎ | 程式
 
 
 
 
定義於標頭檔案 <cstdlib>
[[noreturn]] void _Exit( int exit_code ) noexcept;
(C++11 起)

導致程式正常終止,但不完全清理資源。

不會呼叫具有自動、執行緒區域性和靜態儲存持續時間的變數的解構函式。不會呼叫傳遞給 std::at_quick_exit()std::atexit() 的函式。是否關閉開放資源(如檔案)是實現定義的。

如果 exit_code0EXIT_SUCCESS,則向宿主環境返回一個表示成功終止的實現定義狀態。如果 exit_codeEXIT_FAILURE,則返回一個表示不成功終止的實現定義狀態。在其他情況下,返回實現定義的狀態值。

獨立實現必須提供 std::_Exit

(C++23 起)

目錄

[編輯] 引數

exit_code - 程式的退出狀態

[編輯] 返回值

(無)

[編輯] 注意

儘管自 C++23 起,_Exit 被要求是獨立式的,但它不要求在獨立式的 C 實現中可用。

[編輯] 示例

#include <iostream>
 
class Static
{
public:
    ~Static() 
    {
        std::cout << "Static dtor\n";
    }
};
 
class Local
{
public:
    ~Local() 
    {
        std::cout << "Local dtor\n";
    }
};
 
Static static_variable; // dtor of this object will *not* be called
 
void atexit_handler()
{
    std::cout << "atexit handler\n";
}
 
int main()
{
    Local local_variable; // dtor of this object will *not* be called
 
    // handler will *not* be called
    const int result = std::atexit(atexit_handler);
 
    if (result != 0)
    {
        std::cerr << "atexit registration failed\n";
        return EXIT_FAILURE;
    }
 
    std::cout << "test" << std::endl; // flush from std::endl
        // needs to be here, otherwise nothing will be printed
    std::_Exit(EXIT_FAILURE);
}

輸出

test

[編輯] 另請參閱

導致程式異常終止(不進行清理)
(函式) [編輯]
導致程式正常終止並進行清理
(函式) [編輯]
C 文件 用於 _Exit