]> git.ozlabs.org Git - ccan/blob - ccan/typesafe_cb/test/compile_ok-typesafe_cb-vars.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / typesafe_cb / test / compile_ok-typesafe_cb-vars.c
1 #include <ccan/typesafe_cb/typesafe_cb.h>
2 #include <stdlib.h>
3
4 /* const args in callbacks should be OK. */
5
6 static void _register_callback(void (*cb)(void *arg), void *arg)
7 {
8         (void)cb;
9         (void)arg;
10 }
11
12 #define register_callback(cb, arg)                              \
13         _register_callback(typesafe_cb(void, void *, (cb), (arg)), (arg))
14
15 static void _register_callback_pre(void (*cb)(int x, void *arg), void *arg)
16 {
17         (void)cb;
18         (void)arg;
19 }
20
21 #define register_callback_pre(cb, arg)                                  \
22         _register_callback_pre(typesafe_cb_preargs(void, void *, (cb), (arg), int), (arg))
23
24 static void _register_callback_post(void (*cb)(void *arg, int x), void *arg)
25 {
26         (void)cb;
27         (void)arg;
28 }
29
30 #define register_callback_post(cb, arg)                                 \
31         _register_callback_post(typesafe_cb_postargs(void, void *, (cb), (arg), int), (arg))
32
33 struct undefined;
34
35 static void my_callback(struct undefined *undef)
36 {
37         (void)undef;
38 }
39
40 static void my_callback_pre(int x, struct undefined *undef)
41 {
42         (void)x;
43         (void)undef;
44 }
45
46 static void my_callback_post(struct undefined *undef, int x)
47 {
48         (void)x;
49         (void)undef;
50 }
51
52 int main(void)
53 {
54         struct undefined *handle = NULL;
55         void (*cb)(struct undefined *undef) = my_callback;
56         void (*pre)(int x, struct undefined *undef) = my_callback_pre;
57         void (*post)(struct undefined *undef, int x) = my_callback_post;
58
59         register_callback(cb, handle);
60         register_callback_pre(pre, handle);
61         register_callback_post(post, handle);
62         return 0;
63 }