home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / atexit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-26  |  892 b   |  56 lines

  1. /* ATEXIT.C illustrates:
  2.  *      atexit          onexit
  3.  */
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #define ANSI                /* Comment out to try onexit     */
  8.  
  9. /* Prototypes */
  10. void fn1( void ), fn2( void ), fn3( void ), fn4( void );
  11.  
  12. main()
  13. {
  14.  
  15.     /* atexit is ANSI standard. It returns 0 for success, nonzero
  16.      * for fail.
  17.      */
  18. #ifdef ANSI
  19.     atexit( fn1 );
  20.     atexit( fn2 );
  21.     atexit( fn3 );
  22.     atexit( fn4 );
  23.  
  24.     /* onexit is Microsoft extension. It returns pointer to function
  25.      * for success, NULL for fail.
  26.      */
  27. #else
  28.     onexit( fn1 );
  29.     onexit( fn2 );
  30.     onexit( fn3 );
  31.     onexit( fn4 );
  32. #endif
  33.  
  34.     printf( "This is executed first.\n" );
  35. }
  36.  
  37. void fn1()
  38. {
  39.     printf( "next.\n" );
  40. }
  41.  
  42. void fn2()
  43. {
  44.     printf( "executed " );
  45. }
  46.  
  47. void fn3()
  48. {
  49.     printf( "is " );
  50. }
  51.  
  52. void fn4()
  53. {
  54.     printf( "This " );
  55. }
  56.