Debian Codegraph @

examples/closure.c

raw
1 /*
2 * closure.c - on Linux compile with: gcc closure.c -shared -o closure.so -fPIC
3 */
4
5 #include <stdio.h>
6
7 typedef int (*closure_t)(int);
8 closure_t my_closure = NULL;
9
10 void set_closure(closure_t value)
11 {
12 my_closure = value;
13 }
14
15 int call_closure(int value)
16 {
17 if(my_closure != NULL)
18 return my_closure(value);
19 else
20 fprintf(stderr, "closure is NULL\n");
21 }