RAD Studio
ContentsIndex
PreviousUpNext
atexit

Header File 

stdlib.h 

Category 

Process Control Routines 

Prototype 

int atexit(void (_USERENTRY * func)(void)); 

Description 

Registers termination function. 

atexit registers the function pointed to by func as an exit function. Upon normal termination of the program, exit calls func just before returning to the operating system. fcmp must be used with the _USERENTRY calling convention. 

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

Example  

 #include <stdio.h>
 #include <stdlib.h>
 void exit_fn1(void)
 {
    printf("Exit function #1 called\n");
 }
 void exit_fn2(void)
 {
    printf("Exit function #2 called\n");
 }
 int main(void)
 {
    /* post exit function #1 */
    atexit(exit_fn1);
    /* post exit function #2 */
    atexit(exit_fn2);
    return 0;
 }

Portability

POSIX 
Win32 
ANSI C 
ANSI C++ 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!