1 #include <stdio.h>
2 
3 int
main()4 main() {
5 	/*
6 	 * Case 0: Test if it works at all
7 	 */
8 	struct desig0 {
9 		int	x;
10 		int	y;
11 	} d0 = {
12 		.y = 456,
13 		.x = 123
14 	};
15 
16 	/*
17 	 * Case 1: Test if the initializer sequeyce is correctly
18 	 * continued after the last explicit designation
19 	 */
20 	struct desig1 {
21 		int	x;
22 		int	y;
23 		int	z;
24 	} d1 = {
25 		.y = 456,
26 		789,
27 		.x = 123
28 	};
29 	/*
30 	 * Case 2: Test designated aggregate initializers
31 	 */
32 	struct desig2 {
33 		int		x;
34 		int		y;
35 		struct desig0	nested;
36 		int		z;
37 	} d2 = {
38 		123, /* x */
39 		.nested = { 456, 789 },
40 		1111, /* z */
41 		.y = 4444
42 	};
43 
44 	/*
45 	 * Case 3: Test nested designated initializers and implicit zero-
46 	 * initialization
47 	 */
48 	struct desig3 {
49 		int		x;  /* 4 */
50 		int		y;  /* 8 */
51 		struct desig0	nested;  /* 16 */
52 		int		z;  /* 20 */
53 		int		a;  /* 24 */
54 	} d3 = {
55 		.nested = { .y = 555, .x = 123 },
56 		.z = 123,
57 		.x = 556
58 	};
59 
60 	/*
61 	 * Case 4: Designated array initializers
62 	 */
63 	struct desig4 {
64 		int	x;
65 		int	ar[4];
66 		int	y;
67 	} d4 = {
68 		.ar = { [2] = 2, 3, [0] = 4 },
69 		62,
70 		.x = 11
71 	};
72 	if (d0.x == 123 && d0.y == 456) {
73 		puts("GOOD");
74 	} else {
75 		puts("BUG");
76 	}
77 	if (d1.x == 123 && d1.y == 456 && d1.z == 789) {
78 		puts("GOOD");
79 	} else {
80 		puts("BUG");
81 	}
82 
83 	if (d2.x == 123 && d2.y == 4444 && d2.z == 1111
84 		&& d2.nested.x == 456 && d2.nested.y == 789) {
85 		puts("GOOD");
86 	} else {
87 		puts("BUG");
88 	}
89 
90 	if (d3.x == 556 && d3.y == 0 && d3.z == 123 && d3.a == 0
91 		&& d3.nested.y == 555 && d3.nested.x == 123) {
92 		puts("GOOD");
93 	} else {
94 		puts("BAD");
95 	}
96 
97 	if (d4.x == 11 && d4.ar[0] == 4 && d4.ar[1] == 0 && d4.ar[2] == 2 && d4.ar[3] == 3
98 		&& d4.y == 62) {
99 		puts("GOOD");
100 	} else {
101 		puts("BAD");
102 	}
103 	printf("%d, %d, %d, %d, %d, %d\n",
104 		d4.x, d4.ar[0], d4.ar[1], d4.ar[2], d4.ar[3], d4.y);
105 
106 
107 	return 0;
108 }
109 
110