tcon: add test case for const members.
[ccan] / ccan / tcon / test / compile_ok-sizeof.c
1 #include <ccan/tcon/tcon.h>
2 #include <ccan/build_assert/build_assert.h>
3 #include <stdlib.h>
4
5 struct container {
6         void *p;
7 };
8
9 struct int_container {
10         struct container raw;
11         TCON(int tc);
12 };
13
14 struct charp_and_int_container {
15         struct container raw;
16         TCON(int tc1; char *tc2);
17 };
18
19 int main(int argc, char *argv[])
20 {
21         struct int_container icon;
22         struct charp_and_int_container cicon;
23         TCON_WRAP(struct container, int tc) iconw;
24         TCON_WRAP(struct container, int tc1; char *tc2) ciconw;
25
26         BUILD_ASSERT(tcon_sizeof(&icon, tc) == sizeof(int));
27         BUILD_ASSERT(tcon_sizeof(&cicon, tc1) == sizeof(int));
28         BUILD_ASSERT(tcon_sizeof(&cicon, tc2) == sizeof(char *));
29
30         BUILD_ASSERT(tcon_sizeof(&iconw, tc) == sizeof(int));
31         BUILD_ASSERT(tcon_sizeof(&ciconw, tc1) == sizeof(int));
32         BUILD_ASSERT(tcon_sizeof(&ciconw, tc2) == sizeof(char *));
33
34         return 0;
35 }