home *** CD-ROM | disk | FTP | other *** search
- *****Listing 4*****
-
- #include <stdio.h>
- #include <stdlib.h>
-
- #define SET 1
- #define CLEAR 0
- #define NUMELEM(a) (sizeof(a)/sizeof(a[0]))
-
- void eh(void);
- void cf0(void); /* cleanup functions */
- void cf1(void);
- void cf2(void);
- void cf3(void);
-
- struct status_flags {
- unsigned char flag;
- void (*pfun)(void);
- } handler[] = {
- {CLEAR, cf0},
- {CLEAR, cf1},
- {CLEAR, cf2},
- {CLEAR, cf3}
- };
-
- main()
- {
- atexit(eh);
-
- handler[1].flag = SET;
- handler[3].flag = SET;
- }
-
- void eh(void)
- {
- int i;
-
- for (i = 0; i < NUMELEM(handler); i++) {
- if (handler[i].flag == SET)
- (*handler[i].pfun)();
- }
- }
-
- void cf0(void)
- {
- printf("Inside cf0\n");
- }
-
- ...
-
- void cf3(void)
- {
- printf("Inside cf3\n");
- }
-
- Inside cf1
- Inside cf3
-
-