Files
cppdraft_translate/cppdraft/support/start/term.md
2025-10-25 03:02:53 +03:00

9.4 KiB
Raw Blame History

[support.start.term]

17 Language support library [support]

17.5 Startup and termination [support.start.term]

1

#

[Note 1:

The header declares the functions described in this subclause.

— end note]

🔗

[[noreturn]] void _Exit(int status) noexcept;

2

#

Effects: This function has the semantics specified in the C standard library.

3

#

Remarks: The program is terminated without executing destructors for objects with automatic, thread, or static storage duration and without calling functions passed toatexit() ([basic.start.term]).

The function _Exit is signal-safe.

🔗

[[noreturn]] void abort() noexcept;

4

#

Effects: This function has the semantics specified in the C standard library.

5

#

Remarks: The program is terminated without executing destructors for objects of automatic, thread, or static storage duration and without calling functions passed toatexit() ([basic.start.term]).

The function abort is signal-safe.

🔗

int atexit(c-atexit-handler* f) noexcept; int atexit(atexit-handler* f) noexcept;

6

#

Effects: Theatexit() functions register the function pointed to by f to be called without arguments at normal program termination.

It is unspecified whether a call to atexit() that does nothappen before a call to exit() will succeed.

[Note 2:

The atexit() functions do not introduce a data race ([res.on.data.races]).

— end note]

7

#

Implementation limits: The implementation shall support the registration of at least 32 functions.

8

#

Returns: Theatexit() function returns zero if the registration succeeds, nonzero if it fails.

🔗

[[noreturn]] void exit(int status);

9

#

Effects:

  • (9.1)

    First, objects with thread storage duration and associated with the current thread are destroyed. Next, objects with static storage duration are destroyed and functions registered by callingatexit are called.186 See [basic.start.term] for the order of destructions and calls. (Objects with automatic storage duration are not destroyed as a result of callingexit().)187 If a registered function invoked by exit exits via an exception, the function std::terminate is invoked ([except.terminate]).

  • (9.2)

    Next, all open C streams (as mediated by the function signatures declared in ) with unwritten buffered data are flushed, all open C streams are closed, and all files created by callingtmpfile() are removed.

  • (9.3)

    Finally, control is returned to the host environment. If status is zero orEXIT_SUCCESS, an implementation-defined form of the statussuccessful termination is returned. If status isEXIT_FAILURE, an implementation-defined form of the statusunsuccessful termination is returned. Otherwise the status returned is implementation-defined.188

🔗

int at_quick_exit(c-atexit-handler* f) noexcept; int at_quick_exit(atexit-handler* f) noexcept;

10

#

Effects: The at_quick_exit() functions register the function pointed to by f to be called without arguments when quick_exit is called.

It is unspecified whether a call to at_quick_exit() that does nothappen before all calls to quick_exit will succeed.

[Note 3:

Theat_quick_exit() functions do not introduce a data race ([res.on.data.races]).

— end note]

[Note 4:

The order of registration could be indeterminate if at_quick_exit was called from more than one thread.

— end note]

[Note 5:

Theat_quick_exit registrations are distinct from the atexit registrations, and applications might need to call both registration functions with the same argument.

— end note]

11

#

Implementation limits: The implementation shall support the registration of at least 32 functions.

12

#

Returns: Zero if the registration succeeds, nonzero if it fails.

🔗

[[noreturn]] void quick_exit(int status) noexcept;

13

#

Effects: Functions registered by calls to at_quick_exit are called in the reverse order of their registration, except that a function shall be called after any previously registered functions that had already been called at the time it was registered.

Objects shall not be destroyed as a result of calling quick_exit.

If a registered function invoked by quick_exit exits via an exception, the function std::terminate is invoked ([except.terminate]).

[Note 6:

A function registered via at_quick_exit is invoked by the thread that calls quick_exit, which can be a different thread than the one that registered it, so registered functions cannot rely on the identity of objects with thread storage duration.

— end note]

After calling registered functions, quick_exit shall call _Exit(status).

14

#

Remarks: The function quick_exit is signal-safe when the functions registered with at_quick_exit are.

See also: ISO/IEC 9899:2024, 7.24.4

186)186)

A function is called for every time it is registered.

187)187)

Objects with automatic storage duration are all destroyed in a program whosemain function ([basic.start.main]) contains no objects with automatic storage duration and executes the call toexit().

Control can be transferred directly to such amain function by throwing an exception that is caught inmain.

188)188)

The macros EXIT_FAILURE and EXIT_SUCCESS are defined in .