ATEXIT - specify wrap-up function.

(ANSI Standard)

Usage:

#include <stdlib.h>
stat = atexit(wrapfunc);

Where:

void (*wrapfunc)(void);
points to a "wrap-up" function.
int stat;
is zero if "atexit" succeeds in setting up the wrap-up function. Otherwise, it is a non-zero value.

Description:

The argument of "atexit" is a pointer to a function that takes no arguments and returns no value. This function is called a wrap-up function. It will be invoked when your program terminates by calling "exit" or by returning from "main".

The library does its best to execute your wrap-up functions even if your program aborts (e.g. due to some kind of fault). However, it may not be possible to execute the functions if the program has got itself in too much trouble.

Wrap-up functions are invoked in the reverse of the order in which they were set up with "atexit". For example, if you set up wrap-up functions with

atexit(wrap1);
atexit(wrap2);

the function "wrap2" will be executed before "wrap1".

Wrap-up functions behave as if "main" has just returned, even if the program is actually terminating through a call to exit. As a result, it is an error for a wrap-up function to perform a "longjmp" or to attempt to access objects created with automatic storage duration in another function.

Wrap-up functions are executed before the usual process of flushing and closing files that are still open when the program terminates. Thus, they may make use of these open files. Wrap-up functions are often used to perform special processing on these open files before they are automatically closed. Wrap-up functions are also used to perform miscellaneous "clean-up" operations.

At least 32 wrap-up functions may be set up.

See Also:

expl c lib exit

Copyright © 1996, Thinkage Ltd.