std::_Exit
From cppreference.com
| ヘッダ <cstdlib> で定義 |
||
| [[noreturn]] void _Exit( int exit_code ) noexcept; |
(C++11以降) | |
リソースを完全にクリーンアップすることなく、プログラムの正常終了を引き起こします。
自動、スレッドローカル、静的ストレージ期間を持つ変数のデストラクタは呼び出されません。std::at_quick_exit() または std::atexit() に渡された関数は呼び出されません。ファイルなどの開いているリソースが閉じられるかどうかは実装定義です。
exit_code が 0 または EXIT_SUCCESS の場合、成功終了を示す実装定義のステータスがホスト環境に返されます。exit_code が EXIT_FAILURE の場合、失敗終了を示す実装定義のステータスが返されます。その他の場合、実装定義のステータス値が返されます。
|
フリースタンディング実装は |
(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
[編集] 関連項目
| (クリーンアップせずに)異常なプログラム終了を引き起こす (関数) | |
| クリーンアップを伴う通常のプログラム終了を引き起こす (関数) | |
| _Exit のC ドキュメント
| |