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++ Language Reference - atexit http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   atexit

   Usage
   #include <stdio.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 DOS.

   Example
   #include <stdio.h>

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

   main()
   {
        atexit(xmess);
   }

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

   Return Value
   atexit return 0 if func was successfully registered, non-zero if not.


See Also: exit _exit

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