std::at_quick_exit(3)
β¨ std::at_quick_exit β¨
Welcome to the C++ Standard Libary manual page for std::at_quick_exit, bestie. Itβs giving βregister a function for quick program termination,β and honestly? Iconic. π«Ά
π NAME π
std::at_quick_exit β yes, the name is literally the function name too. The page is called std::at_quick_exit, and itβs all about registering stuff to run when the program dips out via a quick exit. π
π Synopsis π
Defined in header <cstdlib>.
int at_quick_exit( /*atexit-handler*/* func ) noexcept; (1) (since C++11)
int at_quick_exit( /*c-atexit-handler*/* func ) noexcept;
extern "C++" using /*atexit-handler*/ = void(); (2)
(exposition only*)
extern "C" using /*c-atexit-handler*/ = void();
Okay so hereβs the tea: this registers the function pointed to by func to be called on quick program termination (via std::quick_exit). π¦
Calling the function from several threads does not induce a data race. The implementation is guaranteed to support the registration of at least 32 functions. The exact limit is implementation-defined. β¨
π¨ The registered functions will not be called on normal program termination. If a function need to be called in that case, std::atexit must be used. No cap.
π¦ Parameters π¦
funcβ pointer to a function to be called on quick program termination.
π Return value π
0 if the registration succeeds, nonzero value otherwise. Sheβs simple, sheβs clear, sheβs giving successful-registration energy. π
πΈ Notes πΈ
The two overloads are distinct because the types of the parameter func are distinct β language linkage is part of its type. Lowkey a little language-lawyer moment, but we respect it. π
π₯ Example π₯
Run this code π
// Run this code
#include <cstdlib>
#include <iostream>
void f1()
{
std::cout << "pushed first" << std::endl; // flush is intentional
}
extern "C" void f2()
{
std::cout << "pushed second\n";
}
int main()
{
auto f3 = []
{
std::cout << "pushed third\n";
};
std::at_quick_exit(f1);
std::at_quick_exit(f2);
std::at_quick_exit(f3);
std::quick_exit(0);
}
Output:
pushed third
pushed second
pushed first
π 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).quick_exitβ causes quick program termination without completely cleaning up (C++11) (function).- C documentation for
at_quick_exit.
Source/version/date vibe check at the very end: http://cppreference.com Β· 2024.06.10 Β· std::at_quick_exit(3). Bye bestie β go register those quick-exit functions responsibly πβ¨
π¦ 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