Syntax
#include <stdlib.h> onexit_t _onexit(onexit_t func);Description
You can record up to 32 termination functions with calls to _onexit and atexit. If you exceed 32 functions, _onexit returns the value NULL.
Note: For portability, use the ANSI/ISO standard atexit function, which is equivalent to _onexit.
If successful, _onexit returns a pointer to the function; otherwise, it returns a NULL value.
This example specifies and defines four distinct functions that run consecutively at the completion of main.
#include <stdio.h>
#include <stdlib.h>
int fn1(void)
{
printf("next.\n");
}
int fn2(void)
{
printf("run ");
}
int fn3(void)
{
printf("is ");
}
int fn4(void)
{
printf("This ");
}
int main(void)
{
_onexit(fn1);
_onexit(fn2);
_onexit(fn3);
_onexit(fn4);
printf("This is run first.\n");
return 0;
/****************************************************************************
The output should be:
This is run first.
This is run next.
****************************************************************************/
}
Related Information