Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / structscope.c
blob599af4a2f0b6821704fc8ba4f064f01feb8c92a5
1 /* Test struct scoping rules
3 */
5 #include <testfwk.h>
7 /* declare an incomplete struct type */
8 struct tag2;
10 struct tag1 {
11 struct tag1 *mykind;
12 unsigned char x;
13 unsigned char y;
14 struct tag2 *other;
15 } s1;
17 /* complete the previously incomplete type */
18 struct tag2 {
19 unsigned char z;
20 struct tag1 *other;
21 } s2;
23 void
24 test_global(void)
26 s1.mykind = &s1;
27 s1.other = &s2;
28 s2.other = &s1;
29 s1.x = 1;
30 s1.y = 2;
31 s2.z = 3;
32 ASSERT(s2.other->x == 1);
33 ASSERT(s1.other->z == 3);
34 ASSERT(s1.other->other->y == 2);
35 ASSERT(s1.mykind->y == 2);
38 void
39 test_nested(void)
42 struct tag1 {
43 unsigned char a;
44 } ls1;
45 ls1.a=1;
48 struct tag1 ls2; /* should bind to global level tag1 */
49 ls2.x=2;
52 struct tag1 {
53 unsigned char b;
54 struct tag2 *globals2; /* should bind to global level tag2 */
55 } ls3;
56 ls3.b = 3;
57 ls3.globals2 = &s2;
60 struct tag2; /* incomplete local tag */
61 struct tag1 {
62 struct tag2 *locals2; /* should bind to local level s2 tag */
63 } ls4;
64 struct tag2 {
65 unsigned char c;
66 } ls5;
68 ls4.locals2 = &ls5;
69 ls4.locals2->c = 9;
71 s1.x = 0;