std::quick_exit(3)
π NAME π
Okay bestie, this page is for std::quick_exit, and it lives in the C++ Standard Libary corner of the manual (yes, that's the manual name β we're folding it in instead of copying the header line, mwah). It is literally giving "normal program termination, but make it quick and don't do the full cleanup arc." Periodt.
π¦ Synopsis π¦
Defined in header <cstdlib>:
[[noreturn]] void quick_exit( int exit_code ) noexcept;
(since C++11)
So the whole vibe is: this causes normal program termination to occur without completely cleaning the resources. Not a full reset, bestie.
Functions passed to std::at_quick_exit are called in reverse order of their registration. If an exception tries to propagate out of any of the functions, std::terminate is called. After calling the registered functions, it calls std::_Exit(exit_code).
Functions passed to std::atexit are not called. Like, they are not invited to this party. At all. π«Ά
πΈ Parameters πΈ
exit_codeβ exit status of the program.
π Return value π
(none). Literally no return value, bestie. It's [[noreturn]], so it does not come back.
π₯ Example π₯
// Run this 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";
}
Output:
quick_exit handler #2
quick_exit handler #1
π See also π
abortβ causes abnormal program termination (without cleaning up) (function)exitβ causes normal program termination with cleaning up (function)atexitβ registers a function to be called onstd::exit()invocation (function)at_quick_exitβ registers a function to be called onstd::quick_exitinvocation (C++11) (function)- C documentation for
quick_exit
source/version: http://cppreference.com Β· date: 2024.06.10 β stay quick, stay iconic π
β¨π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms