patch type_to_str to handle complex function-ptr decls better
[tinycc.git] / tests / tests2 / 94_generic.c
blob4804f6595d97eed724174281c138a3367e6c9d13
1 #include <stdio.h>
3 const int a = 0;
5 struct a {
6 int a;
7 };
9 struct b {
10 int a;
13 int a_f()
15 return 20;
18 int b_f()
20 return 10;
23 typedef int (*fptr)(int);
24 int foo(int i)
26 return i;
29 typedef int int_type1;
31 #define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123);
33 int main()
35 int i = 0;
36 signed long int l = 2;
37 struct b titi;
38 const int * const ptr;
39 const char *ti;
40 int_type1 i2;
42 i = _Generic(a, int: a_f, const int: b_f)();
43 printf("%d\n", i);
44 i = _Generic(a, int: a_f() / 2, const int: b_f() / 2);
45 printf("%d\n", i);
46 i = _Generic(ptr, int *:1, int * const:2, default:20);
47 printf("%d\n", i);
48 i = gen_sw(a);
49 printf("%d\n", i);
50 i = _Generic(titi, struct a:1, struct b:2, default:20);
51 printf("%d\n", i);
52 i = _Generic(i2, char: 1, int : 0);
53 printf("%d\n", i);
54 i = _Generic(a, char:1, int[4]:2, default:5);
55 printf("%d\n", i);
56 i = _Generic(17, int :1, int **:2);
57 printf("%d\n", i);
58 i = _Generic(17L, int :1, long :2, long long : 3);
59 printf("%d\n", i);
60 i = _Generic("17, io", char *: 3, const char *: 1);
61 printf("%d\n", i);
62 i = _Generic(ti, const unsigned char *:1, const char *:4, char *:3,
63 const signed char *:2);
64 printf("%d\n", i);
65 printf("%s\n", _Generic(i + 2L, long: "long", int: "int",
66 long long: "long long"));
67 i = _Generic(l, long: 1, int: 2);
68 printf("%d\n", i);
69 i = _Generic(foo, fptr: 3, int: 4);
70 printf("%d\n", i);
71 return 0;