]> 4ch.mooo.com Git - 16.git/blob - 16/16/SCRC/funptr.c
cleaned up the repo from debugging watcom2 ^^
[16.git] / 16 / 16 / SCRC / funptr.c
1 #include <stdio.h>
2
3 /* a function pointer to a void pointer which takes one int argument */
4 typedef void (*trigger)(int);
5
6
7 /* invokes a list of functions from an array */
8 void invokeTriggers(trigger *list, int n) {
9     int i;
10     trigger *tf = list;
11
12     for(i=0; i<n; i++) {
13         //invoke each function
14         (*tf)(i);
15         tf++;
16     }
17 }
18
19
20 void f1(int x) {
21      printf("f1: %d\n", x);
22 }
23
24 void f2(int x) {
25     printf("f2: %d\n", x);
26 }
27
28
29 void main()  {
30    trigger list[3];
31
32    /* set up the list */
33    list[0] = f1;
34    list[1] = f2;
35    list[2] = f1;
36
37    invokeTriggers(list, 3);
38
39    return;
40 }
41
42