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