1 | #include <stdio.h>
|
---|
2 |
|
---|
3 | const int a = 0;
|
---|
4 |
|
---|
5 | struct a {
|
---|
6 | int a;
|
---|
7 | };
|
---|
8 |
|
---|
9 | struct b {
|
---|
10 | int a;
|
---|
11 | };
|
---|
12 |
|
---|
13 | int a_f()
|
---|
14 | {
|
---|
15 | return 20;
|
---|
16 | }
|
---|
17 |
|
---|
18 | int b_f()
|
---|
19 | {
|
---|
20 | return 10;
|
---|
21 | }
|
---|
22 |
|
---|
23 | typedef int int_type1;
|
---|
24 |
|
---|
25 | #define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123);
|
---|
26 |
|
---|
27 | int main()
|
---|
28 | {
|
---|
29 | int i = 0;
|
---|
30 | signed long int l = 2;
|
---|
31 | struct b titi;
|
---|
32 | const int * const ptr;
|
---|
33 | const char *ti;
|
---|
34 | int_type1 i2;
|
---|
35 |
|
---|
36 | i = _Generic(a, int: a_f, const int: b_f)();
|
---|
37 | printf("%d\n", i);
|
---|
38 | i = _Generic(a, int: a_f() / 2, const int: b_f() / 2);
|
---|
39 | printf("%d\n", i);
|
---|
40 | i = _Generic(ptr, int *:1, int * const:2, default:20);
|
---|
41 | printf("%d\n", i);
|
---|
42 | i = gen_sw(a);
|
---|
43 | printf("%d\n", i);
|
---|
44 | i = _Generic(titi, struct a:1, struct b:2, default:20);
|
---|
45 | printf("%d\n", i);
|
---|
46 | i = _Generic(i2, char: 1, int : 0);
|
---|
47 | printf("%d\n", i);
|
---|
48 | i = _Generic(a, char:1, int[4]:2, default:5);
|
---|
49 | printf("%d\n", i);
|
---|
50 | i = _Generic(17, int :1, int **:2);
|
---|
51 | printf("%d\n", i);
|
---|
52 | i = _Generic(17L, int :1, long :2, long long : 3);
|
---|
53 | printf("%d\n", i);
|
---|
54 | i = _Generic("17, io", char *: 3, const char *: 1);
|
---|
55 | printf("%d\n", i);
|
---|
56 | i = _Generic(ti, const unsigned char *:1, const char *:4, char *:3,
|
---|
57 | const signed char *:2);
|
---|
58 | printf("%d\n", i);
|
---|
59 | printf("%s\n", _Generic(i + 2L, long: "long", int: "int",
|
---|
60 | long long: "long long"));
|
---|
61 | i = _Generic(l, long: 1, int: 2);
|
---|
62 | printf("%d\n", i);
|
---|
63 | return 0;
|
---|
64 | }
|
---|