std::quick_exit(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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 on std::exit() invocation (function)
  • at_quick_exit β€” registers a function to be called on std::quick_exit invocation (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