]> git.sur5r.net Git - cc65/blob - test/val/anon-struct1.c
Proper warnings for "risky" gotos.
[cc65] / test / val / anon-struct1.c
1 /*
2   !!DESCRIPTION!! Make sure that structs/unions know the sizes of anonymous struct/union members
3   !!ORIGIN!!      cc65 regression tests
4   !!LICENCE!!     Public Domain
5   !!AUTHOR!!      Greg King
6 */
7
8 /*
9   see https://github.com/cc65/cc65/issues/641
10 */
11
12 #include <stdio.h>
13
14 static unsigned char fails = 0;
15
16 typedef struct {
17     short s1;
18     struct {
19         int i1;
20         long l1;
21         char c1;
22     };
23     char c2;
24 } s1_t;
25
26 typedef struct {
27     short s1;
28     union {
29         int i1;
30         long l1;
31         char c1;
32     };
33     char c2;
34 } s2_t;
35
36 typedef union {
37     short s1;
38     struct {
39         int i1;
40         long l1;
41         char c1;
42     };
43     char c2;
44 } u1_t;
45
46 typedef union {
47     short s1;
48     union {
49         int i1;
50         long l1;
51         char c1;
52     };
53     char c2;
54 } u2_t;
55
56 static s1_t s1;
57 static s2_t s2;
58 static u1_t u1;
59 static u2_t u2;
60
61 /* We use "variables" in the comparisons, so that we can avoid "constant
62 ** comparison" and "Unreachable code" warnings (the second one currently
63 ** can't be suppressed).
64 */
65
66 static size_t const four = 4;
67 static size_t const seven = 7;
68 static size_t const ten = 10;
69
70 int main(void)
71 {
72     /* Check the types' sizes. */
73
74     if (sizeof (s1_t) != ten) {
75         printf("s1_t size is %u; it should be 10.\n", sizeof (s1_t));
76         ++fails;
77     }
78     if (sizeof (s2_t) != seven) {
79         printf("s2_t size is %u; it should be 7.\n", sizeof (s2_t));
80         ++fails;
81     }
82     if (sizeof (u1_t) != seven) {
83         printf("u1_t size is %u; it should be 7.\n", sizeof (u1_t));
84         ++fails;
85     }
86     if (sizeof (u2_t) != four) {
87         printf("u2_t size is %u; it should be 4.\n", sizeof (u2_t));
88         ++fails;
89     }
90
91     /* Check the variables' sizes. */
92
93     if (sizeof s1 != ten) {
94         printf("s1 size is %u; it should be 10.\n", sizeof s1);
95         ++fails;
96     }
97     if (sizeof s2 != seven) {
98         printf("s2 size is %u; it should be 7.\n", sizeof s2);
99         ++fails;
100     }
101     if (sizeof u1 != seven) {
102         printf("u1 size is %u; it should be 7.\n", sizeof u1);
103         ++fails;
104     }
105     if (sizeof u2 != four) {
106         printf("u2 size is %u; it should be 4.\n", sizeof u2);
107         ++fails;
108     }
109
110     return fails;
111 }