]> pd.if.org Git - lice/blob - tests/typeof.c
autocommit for files dated 2014-11-17 20:15:26
[lice] / tests / typeof.c
1 // typeof keyword
2
3 int main(void) {
4     // basic usage of it
5     typeof(int) a = 1024;
6     expecti(a, 1024);
7
8     typeof(a) b = 2048;
9     expecti(b, 2048);
10
11     __typeof__(int) aa = 1024;
12     expecti(aa, 1024);
13
14     __typeof__(aa) bb = 2048;
15     expecti(bb, 2048);
16
17
18     // arrays?
19     char c[] = "hello";
20     typeof(c) d = "world";
21
22     expectstr(d, "world");
23     expecti(sizeof(d), 6);
24
25     typeof(typeof (char *)[4]) odd;
26     expecti(sizeof(odd)/sizeof(*odd), 4);
27
28
29     char cc[] = "hello";
30     __typeof__(cc) dd = "world";
31
32     expectstr(dd, "world");
33     expecti(sizeof(dd), 6);
34
35     __typeof__(__typeof__ (char *)[4]) oddd;
36     expecti(sizeof(oddd)/sizeof(*oddd), 4);
37
38     // struct union enum
39     typeof(struct { int a; }) __1 = { .a = 1 };
40     typeof(union  { int a; }) __2 = { .a = 1 };
41     typeof(enum   { A1,B2  }) __3 = { B2 };
42
43     expecti(__1.a, 1);
44     expecti(__2.a, 1);
45     expecti(__3,   B2);
46
47     __typeof__(struct { int a;  }) __11 = { .a = 1 };
48     __typeof__(union  { int a;  }) __22 = { .a = 1 };
49     __typeof__(enum   { A11,B22 }) __33 = { B22 };
50
51     expecti(__11.a, 1);
52     expecti(__22.a, 1);
53     expecti(__33,   B22);
54
55     return 0;
56 }