quick_exit
for Normal Program Termination without Completely Cleaning Up
Defined in header <stdlib.h>
.
_Noreturn void quick_exit( int exit_code ); // since C11 and until C23 [[noreturn]] void quick_exit( int exit_code ); // since C23
Causes normal program termination to occur without completely cleaning the resources.
Functions passed to at_quick_exit
are called in reverse order of their registration. After calling the registered functions, calls _Exit(exit_code)
.
Functions passed to atexit
or signal handlers passed to signal
are not called.
Example
#include <stdlib.h> #include <stdio.h> void f1(void) { puts("pushed first"); fflush(stdout); } void f2(void) { puts("pushed second"); } void f3(void) { puts("won't be called"); } int main(void) { at_quick_exit(f1); at_quick_exit(f2); atexit(f3); quick_exit(0); }
Function at_quick_exit()
Defined in header <stdlib.h>
int at_quick_exit( void (*func)(void) ); // since C11
Registers the function pointed to by func to be called on quick program termination (via 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, atexit must be used.
Return Value
0
if the registration succeeds, nonzero value otherwise.
Example
#include <stdlib.h> #include <stdio.h> void f1(void) { puts("pushed first"); fflush(stdout); } void f2(void) { puts("pushed second"); } int main(void) { at_quick_exit(f1); at_quick_exit(f2); quick_exit(0); }
[...]