]> git.sur5r.net Git - cc65/blob - test/ref/fields.c
794a819240b588aa1c174b9cbe98f2f5083e9264
[cc65] / test / ref / fields.c
1 /*
2   !!DESCRIPTION!! bitfield test
3   !!ORIGIN!!      LCC 4.1 Testsuite
4   !!LICENCE!!     own, freely distributeable for non-profit. read CPYRIGHT.LCC
5 */
6
7 #ifdef NO_BITFIELDS
8
9 main()
10 {
11         printf("NO_BITFIELDS\n\r");
12 }
13
14 #else
15
16 #ifdef SIZEOF_INT_16BIT
17
18 #ifdef REFCC
19 #include <stdint.h>
20 struct foo {
21         int16_t a;
22         char b;
23         int16_t x : 12, y : 4;
24         int16_t zz : 1, : 0, : 4, z : 3;
25         char c;
26 } x = { 1, 2, 3, 4, 5, 6 };
27
28 struct baz { uint16_t a:2, b:4, c:16;} y = { 7, 8, 9};
29 int16_t i = 8;
30
31 #else
32
33 struct foo {
34         int a;
35         char b;
36         int x : 12, y : 4;
37         int zz : 1, : 0, : 4, z : 3;
38         char c;
39 } x = { 1, 2, 3, 4, 5, 6 };
40
41 struct baz { unsigned int a:2, b:4, c:16;} y = { 7, 8, 9};
42 int i = 8;
43 #endif
44
45 #else
46 struct foo {
47         int a;
48         char b;
49         int x : 12, y : 4, : 0, : 4, z : 3;
50         char c;
51 } x = { 1, 2, 3, 4, 5, 6 };
52
53 struct baz { unsigned int a:2, b:4, c:32;} y = { 7, 8, 9};
54 int i = 16;
55 #endif
56
57 #ifdef NO_IMPLICIT_FUNC_PROTOTYPES
58 f1(struct baz *p);
59 f2(struct baz *p);
60 #endif
61
62 main()
63 {
64         printf("x = %d b:%d %d %d %d c:%d\n", x.a, x.b, x.x, x.y, x.z, x.c);
65         printf("y = %d b:%d c:%d\n", y.a, y.b, y.c);
66         x.y = i;
67         x.z = 070;
68         printf("x = %d b:%d %d %d %d c:%d\n", x.a, x.b, x.x, x.y, x.z, x.c);
69         y.a = 2;
70         y.c = i;
71         printf("y = %d b:%d c:%d\n", y.a, y.b, y.c);
72 #ifdef CAST_STRUCT_PTR
73         f2((struct baz *)&x);
74 #else
75         f2(&x);
76 #endif
77         return 0;
78 }
79
80 f1(struct baz *p) {
81         p->a = p->b = 0;
82         if (p->b)
83                 printf("p->b != 0!\n");
84         p->a = 0x3; p->b = 0xf;
85         printf("p->a = 0x%x, p->b = 0x%x\n", p->a, p->b);
86 }
87 f2(struct baz *p) {
88         p->a = (i==0);
89         p->b = (f1(p),0);
90 }
91
92 #endif