Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>atexit</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
atexit

Usage

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

Description

   atexit registers the function func such that when the program terminates
   normally by returning from main or by calling exit, the registered
   functions are called. A maximum of 32 functions can be registered by

   successive calls to the atexit function. Registered functions are passed
   no arguments and no values are returned.

   The registered functions must have "C" linkage. Functions compiled with
   the C++ compiler must be specified as having "C" linkage in order to be
   registered with atexit. See the example for more information.

   When exit is called (either explicitly or via the return from main):

   1.  Functions registered via atexit are called in the reverse order
       that they were registered. (last in, first out)

   2.  If this is a C++ program, the static destructors are called.

   3.  All open streams are flushed and closed.

   4.  _exit is called with the exit status, which returns to the
       operating system.

Example 

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

   #if __cplusplus
       extern "C"              /* force C linkage */
   #endif
       void xmess(void);

   int main()
   {

       atexit(xmess);
       return EXIT_SUCCESS;
   }

   void xmess(void)
   {
       printf("Program exiting.\n");
   }


Return Value

   atexit returns 0 if func was successfully registered, non-zero if not.

See Also

   exit, _exit


See Also: exit _exit

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson