1 int
main()2 main()
3 {
4 /* Empty initializers and compound literals - gcc */
5 struct empty2 {int i;};
6 struct empty2 k = {}; /* Empty initializer */
7 k = (struct empty2){}; /* Empty compound literal */
8
9 int i;
10
11 typedef struct empty {} ES;
12 ES k2 = {}; /* Empty initializer */
13 k2 = (ES){}; /* Empty compound literal */
14
15 /* Simple designators and compound literals */
16 struct point { int x, y;} *p2, p = {.y = 1, .x = 2};
17 p = (struct point){.x = 4, .y = 8};
18 p2 = &(struct point){.x = 14, .y = 18};
19 p2 = &(struct point){.y = 14, 18}; /* Excess elements */
20
21 /* Nested designators and compound literals */
22 struct color {int r, g, b; };
23 struct rectangle {
24 struct point tl, br;
25 struct color c;
26 } r = {
27 .br = { .y = 4, .x = 8 },
28 .c = { .r = 4, .b = 1, .g = 12},
29 .tl = { .x = 1, .y = 2 },
30 };
31
32 r = (struct rectangle){
33 .br = { .y = 4, .x = 8 },
34 .c = { .r = 4, .b = 1, .g = 12},
35 .tl = { .x = 1, .y = 2 }
36 };
37 r = (struct rectangle){
38 { .y = 4, .x = 8 },
39 { .x = 1, .y = 2 },
40 { .r = 4, .b = 1, .g = 12},
41 };
42
43 r = (struct rectangle){
44 .br = (struct point){ .y = 4, .x = 8 },
45 .c = (struct color){ .r = 4, .b = 1, .g = 12},
46 .tl = (struct point){ .x = 1, .y = 2 }
47 };
48
49 r = (struct rectangle){
50 .tl = { .x = 1, .y = 2 },
51 .br = (struct point){ .y = 4, .x = 8 },
52 { .r = 4, .b = 1, .g = 12},
53 };
54 }
55