_onexit

Registers a routine to be called at exit time.

_onexit_t_onexit(_onexit_tfunc**);**

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);

void main( void )
{
   _onexit( fn1 );
   _onexit( fn2 );
   _onexit( fn3 );
   _onexit( fn4 );
   printf( "This is executed first.\n" );
}

int fn1()
{
   printf( "next.\n" );
   return 0;
}

int fn2()
{
   printf( "executed " );
   return 0;
}

int fn3()
{
   printf( "is " );
   return 0;
}

int fn4()
{
   printf( "This " );
   return 0;
}

Output

This is executed first.
This is executed next.

Process and Environment Control Routines

See Also   atexit, exit