source: CIVL/examples/experimental/compound_initializer_corners.cvl@ beab7f2

main test-branch
Last change on this file since beab7f2 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include <assert.h>
2
3struct T {
4 int w;
5 struct {
6 int x;
7 int y;
8 };
9 int z;
10};
11
12union U {
13 int w;
14 struct {
15 int x;
16 int y;
17 };
18 int z;
19};
20
21int c[10] = {[2]=3};
22
23int main() {
24 struct T a0 = {1, 2, 3, 4};
25 struct T a1 = {1, {2, 3}, 4};
26 struct T a2 = {1, {2, 3}}; // .w = 1 .x = 2 .y = 3
27 /* struct T a3 = {{2, 3}, 4};
28 *
29 * The brace is not matching the sub-struct correctly. C11
30 * Sec. 6.7.9 (20) describes such situation. My understand of C11
31 * is that "{2, 3}" will be used to initialize the first named
32 * member which is w. Unnamed members will not be initialized.
33 *
34 * CIVL reports error for this case while both GCC and Clang accepts.
35 */
36 /* struct T a4 = {.x = 1, .y = 2, .x = 3};
37 * Can unnamed members be initialized with designators ?
38 * CIVL reports error for this case while both GCC and Clang accepts.
39 */
40
41 assert(a2.y == 3 && a2.z == 0);
42 // assert(a3.w == 2 && a3.x == 4);
43 // assert(a4.x == 3 && a4.y == 2);
44
45 union U b0 = {4, 2, 3, 1}; // start from the first member .w = 1, ignore rest
46 // same as above, GCC doesn't accepts this though according to C11 it is acceptable, CIVL accpets this:
47 union U b1 = {1, {2, 3}, 4};
48 // CIVL reports error for the followings:
49 // union U b2 = {{2, 3}, 4}; brace unmatch, CIVL reports error for this
50 // union U b3 = {{2, 3}}; same as above
51 // union U b4 = {.x = 1, .z = 2};// override to .z = 2
52
53 assert(b0.w == 4);
54 assert(b1.w == 1);
55 //assert(b2.w == 2);
56 //assert(b3.w == 2);
57 //assert(b4.z == 2);
58}
Note: See TracBrowser for help on using the repository browser.