The C at_quick_exit() function registers a quick-termination callback. Each successful call adds one callback to the quick_exit() stack. The callback must return normally and should avoid unsafe assumptions about program state.
This function is declared in <stdlib.h>. Its contract matters as much as its call: validate every required precondition, check any documented sentinel, and keep ownership or host effects clear in the surrounding code. Success is reported by 0 and the callback is registered. Failure is a nonzero result; the callback must then be treated as unregistered. The examples below move from the direct call to an edge condition and a practical use.
Syntax
Start with this concrete at_quick_exit() call:
C
at_quick_exit(cleanup);
Call
What it does
at_quick_exit(cleanup);
Registers a quick-termination callback using the concrete values shown.
Include <stdlib.h>. Also include headers that declare any types, limits, locale tools, or I/O functions used around the call.
Library declaration
C
int at_quick_exit(void (*function)(void));
Parameters
Parameter
Description
function
Pointer to a no-argument, no-return function to run during quick_exit().
Return Value
Return Value
Description
0
Registration succeeded.
Nonzero
The callback could not be registered.
C Examples
Example 1 — Register one callback
This complete program demonstrates a distinct part of the at_quick_exit() contract and checks the result or precondition that matters for the scenario.
Step 1. Define a callback with no parameters and no return value.
Step 2. Register it and check at_quick_exit() for zero.
Step 3. Perform the program's ordinary work using explicitly flushed stderr for this visible quick-exit demonstration.
Step 4. Normal quick-exit processing invokes the callback.
Example 2 — Observe reverse order
This complete program demonstrates a distinct part of the at_quick_exit() contract and checks the result or precondition that matters for the scenario.
This complete program demonstrates a distinct part of the at_quick_exit() contract and checks the result or precondition that matters for the scenario.
Step 3. Continue only after zero confirms registration.
Step 4. The selected termination path runs the confirmed callback.
Frequently Asked Questions
at_quick_exit() registers a quick-termination callback. Each successful call adds one callback to the quick_exit() stack. The callback must return normally and should avoid unsafe assumptions about program state.
Include <stdlib.h> before calling at_quick_exit().
Success is reported by 0 and the callback is registered. Failure is a nonzero result; the callback must then be treated as unregistered.
Callbacks run only for quick_exit(), in reverse registration order. They do not run for exit(), _Exit(), abort(), or return from main.
The function is specified by the C standard library. Exact limits, locale behavior, environment behavior, allocation capacity, or host effects can still vary where relevant.