std::_Exit(3)

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

πŸ¦‹ std::_Exit(3) πŸ¦‹

okay so bestie, welcome to std::_Exit(3) from the C++ Standard Libary β€” yes, that's the manual name, and this page is about the most β€œI'm out, no cleanup” function ever. no cap 🫢

πŸ‘‘ NAME πŸ‘‘

std::_Exit β€” literally std::_Exit, that's the name, bestie πŸ’…

✨ Synopsis ✨

Defined in header <cstdlib>
[[noreturn]] void _Exit( int exit_code ) noexcept;  (since C++11)

πŸ’– Description πŸ’–

So here's the tea: std::_Exit causes normal program termination to occur without completely cleaning the resources. it's giving β€œwe're leaving right now, no packing” πŸ’¨

Destructors of variables with automatic, thread local and static storage durations are not called. Functions passed to std::at_quick_exit() or std::atexit() are not called. Whether open resources such as files are closed is implementation defined. important caveat, bestie β€” that last bit is not something this page promises.

If exit_code is 0 or EXIT_SUCCESS, an implementation-defined status indicating successful termination is returned to the host environment. If exit_code is EXIT_FAILURE, an implementation-defined status, indicating unsuccessful termination, is returned. In other cases implementation-defined status value is returned. implementation-defined girlies, you know how it is 🌸

πŸŽ€ Parameters πŸŽ€

  • exit_code β€” exit status of the program. that's the whole parameter list, bestie πŸ“

πŸ’œ Return value πŸ’œ

(none) β€” literally nothing comes back, it's a [[noreturn]] situation, so don't wait up 😭

πŸ’» Example πŸ’»

// Run this code β€” go go go:

       // Run this code

        #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);
        }

πŸ“ Output: πŸ“

        test

🌈 See also 🌈

  • abort β€” causes abnormal program termination (without cleaning up) (function) πŸ’€
  • exit β€” causes normal program termination with cleaning up (function) 🧚
  • C documentation for _Exit β€” yes, the C docs, go look bestie πŸ“š

mwah πŸ’‹ this lil page comes from http://cppreference.com, version/date 2024.06.10, and the page is literally std::_Exit(3) β€” byeee ✨

πŸ“¦ where this page comes from