For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
To generate an ANSI-compliant application, use the ANSI-standard atexit function (rather than the similar _onexit function).
Return Value
atexit returns 0 if successful, or a nonzero value if an error occurs.
Parameter
func
Function to be called
Remarks
The atexit function is passed the address of a function (func) to be called when the program terminates normally. Successive calls to atexit create a register of functions that are executed in LIFO (last-in-first-out) order. The functions passed to atexit cannot take parameters. atexit and _onexit use the heap to hold the register of functions. Thus, the number of functions that can be registered is limited only by heap memory.
Example
/* ATEXIT.C: This program pushes four functions onto
* the stack of functions to be executed when atexit
* is called. When the program exits, these programs
* are executed on a "last in, first out" basis.
*/
See Also abort, exit, _onexit
------------------------------------------------------------------------
_onexit
Registers a routine to be called at exit time.
_onexit_t _onexit( _onexit_t func );
Routine Required Header Compatibility
_onexit <stdlib.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
_onexit returns a pointer to the function if successful, or NULL if there is no space to store the function pointer.
Parameter
func
Pointer to function to be called at exit
Remarks
The _onexit function is passed the address of a function (func) to be called when the program terminates normally. Successive calls to _onexit create a register of functions that are executed in LIFO (last-in-first-out) order. The functions passed to _onexit cannot take parameters.
_onexit is a Microsoft extension. For ANSI portability use atexit.
Example
/* ONEXIT.C */
#include <stdlib.h>
#include <stdio.h>
/* Prototypes */
int fn1(void), fn2(void), fn3(void), fn4 (void);