]> 4ch.mooo.com Git - 16.git/blobdiff - 16/SCRC/funptr.c
modified: 16/Project 16.bfproject
[16.git] / 16 / SCRC / funptr.c
diff --git a/16/SCRC/funptr.c b/16/SCRC/funptr.c
new file mode 100644 (file)
index 0000000..90fcbde
--- /dev/null
@@ -0,0 +1,42 @@
+#include <stdio.h>
+
+/* a function pointer to a void pointer which takes one int argument */
+typedef void (*trigger)(int);
+
+
+/* invokes a list of functions from an array */
+void invokeTriggers(trigger *list, int n) {
+    int i;
+    trigger *tf = list;
+
+    for(i=0; i<n; i++) {
+       //invoke each function
+       (*tf)(i);
+       tf++;
+    }
+}
+
+
+void f1(int x) {
+     printf("f1: %d\n", x);
+}
+
+void f2(int x) {
+    printf("f2: %d\n", x);
+}
+
+
+void main()  {
+   trigger list[3];
+
+   /* set up the list */
+   list[0] = f1;
+   list[1] = f2;
+   list[2] = f1;
+
+   invokeTriggers(list, 3);
+
+   return;
+}
+
+