COHERENT manpages
This page displays the COHERENT manpage for atexit() [Register a function to be called when the program exits].
List of available manpages
Index
atexit() -- General Function (libc)
Register a function to be called when the program exits
#include <stdlib.h>
int atexit(void (function)
void (*function)();
atexit() registers one or more functions to be called when the program
exits. These registered functions can, for example, perform clean-up
beyond what is ordinarily performed when a program exits. atexit() can
register up to 32 functions.
function points to the function to be called. A registered function takes
no arguments and returns nothing.
The functions that atexit() registers are called when the program exits
normally, i.e., when the function exit() is called or when main() returns.
They are called in reverse order of registration.
atexit() returns zero if function could be registered, and a value other
than zero if it could not.
Example
This example registers two functions to be executed upon exiting: one
displays a message, and the other waits for the user to press a key before
terminating.
#include <stdlib.h>
#include <stdio.h>
void
lastgasp()
{
fprintf(stderr, "Type return to continue");
}
void
get1()
{
getchar();
}
main()
{
/* set up get1() as last exit routine */
atexit(get1);
/* set up lastgasp() as exit routine */
atexit(lastgasp);
/* exit, which invokes exit routines */
exit(EXIT_SUCCESS);
}
See Also
exit(),
libc
ANSI Standard, §7.10.4.2






