Typesafe callback infrastructure.
[ccan] / typesafe_cb / test / compile_fail-cast_if_type-callback.c
1 #include "typesafe_cb/typesafe_cb.h"
2 #include <stdlib.h>
3
4 static void _callback(void (*fn)(void *arg), void *arg)
5 {
6         fn(arg);
7 }
8
9 #define callback(fn, arg)                                               \
10         _callback(cast_if_type((fn), void (*)(typeof(arg)), void (*)(void *)), \
11                   arg)
12
13 static void my_callback(char *p)
14 {
15 }
16
17 int main(int argc, char *argv[])
18 {
19         callback(my_callback, "hello world");
20
21 #ifdef FAIL
22         /* Must be a char * */
23         callback(my_callback, my_callback);
24 #endif
25         return 0;
26 }