home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_06 / 8n06030a < prev    next >
Text File  |  1990-04-18  |  761b  |  59 lines

  1. *****Listing 4*****
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. #define SET 1
  7. #define CLEAR 0
  8. #define NUMELEM(a) (sizeof(a)/sizeof(a[0]))
  9.  
  10. void eh(void);
  11. void cf0(void);    /* cleanup functions */
  12. void cf1(void);
  13. void cf2(void);
  14. void cf3(void);
  15.  
  16. struct status_flags {
  17.     unsigned char flag;
  18.     void (*pfun)(void);
  19. } handler[] = {
  20.     {CLEAR, cf0},
  21.     {CLEAR, cf1},
  22.     {CLEAR, cf2},
  23.     {CLEAR, cf3}
  24. };
  25.  
  26. main()
  27. {
  28.     atexit(eh);
  29.  
  30.     handler[1].flag = SET;
  31.     handler[3].flag = SET;
  32. }
  33.  
  34. void eh(void)
  35. {
  36.     int i;
  37.  
  38.     for (i = 0; i < NUMELEM(handler); i++) {
  39.         if (handler[i].flag == SET)
  40.             (*handler[i].pfun)();
  41.     }
  42. }
  43.  
  44. void cf0(void)
  45. {
  46.     printf("Inside cf0\n");
  47. }
  48.  
  49. ...
  50.  
  51. void cf3(void)
  52. {
  53.     printf("Inside cf3\n");
  54. }
  55.  
  56. Inside cf1
  57. Inside cf3
  58.  
  59.