Borland C++ reference

atexit

raw OCR

Registers termination function.

Defined in header <stdlib.h>

Syntax

#include <stdlib.h>
int atexit(void (*/wnc)(void));

Portability

DOSUNIXWindowsANSI CC++ only
■■■

Remarks

atexit registers the function pointed to by func as an exit function. Upon normal termination of the program, exit calls {*func)0 just before returning to the operating system.

Each call to atexit registers another exit function. Up to 32 functions can be registered. They are executed on a last-in, first-out basis (that is, the last function registered is the first to be executed).

Return value

atexit returns 0 on success and nonzero on failure (no space left to register the function).

See also

Example

#include <stdio.h>
#include <stdlib.h>

void exit_fnl (void)

   printfC'Exit  function #1 called\n");

void exit_fn2 (void)

   printfC'Exit  function #2 called\n");

int main (void)

   /* post exit function  #1 */
   atexit (exit_fnl);
   /* post exit function  #2 */
   atexit (exit_fn2);
   printfC'Done in main\n");
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.