* lib/gdb.exp (CFLAGS): Remove, unreferenced.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / bitfields.c
CommitLineData
ef44eed1
SS
1/* Test program to test bit field operations */
2
3/* For non-ANSI compilers, use plain ints for the signed bit fields. However,
4 whether they actually end up signed or not is implementation defined, so
5 this may cause some tests to fail. But at least we can still compile
6 the test program and run the tests... */
7
8#ifndef __STDC__
9#define signed /**/
10#endif
11
12struct fields
13{
14 unsigned char uc ;
15 signed int s1 : 1;
16 unsigned int u1 : 1;
17 signed int s2 : 2;
18 unsigned int u2 : 2;
19 signed int s3 : 3;
20 unsigned int u3 : 3;
21 signed int s9 : 9;
22 unsigned int u9 : 9;
23 signed char sc ;
24} flags;
25
26void break1 ()
27{
28}
29
30void break2 ()
31{
32}
33
34void break3 ()
35{
36}
37
38void break4 ()
39{
40}
41
42void break5 ()
43{
44}
45
46void break6 ()
47{
48}
49
50void break7 ()
51{
52}
53
54void break8 ()
55{
56}
57
58void break9 ()
59{
60}
61
62void break10 ()
63{
64}
65
66/* This is used by bitfields.exp to determine if the target understands
67 signed bitfields. */
68int i;
69
70int main ()
71{
72 /* For each member, set that member to 1, allow gdb to verify that the
73 member (and only that member) is 1, and then reset it back to 0. */
74
75 flags.uc = 1;
76 break1 ();
77 flags.uc = 0;
78
79 flags.s1 = 1;
80 break1 ();
81 flags.s1 = 0;
82
83 flags.u1 = 1;
84 break1 ();
85 flags.u1 = 0;
86
87 flags.s2 = 1;
88 break1 ();
89 flags.s2 = 0;
90
91 flags.u2 = 1;
92 break1 ();
93 flags.u2 = 0;
94
95 flags.s3 = 1;
96 break1 ();
97 flags.s3 = 0;
98
99 flags.u3 = 1;
100 break1 ();
101 flags.u3 = 0;
102
103 flags.s9 = 1;
104 break1 ();
105 flags.s9 = 0;
106
107 flags.u9 = 1;
108 break1 ();
109 flags.u9 = 0;
110
111 flags.sc = 1;
112 break1 ();
113 flags.sc = 0;
114
115 /* Fill alternating fields with all 1's and verify that none of the bits
116 "bleed over" to the other fields. */
117
118 flags.uc = 0xFF;
119 flags.u1 = 0x1;
120 flags.u2 = 0x3;
121 flags.u3 = 0x7;
122 flags.u9 = 0x1FF;
123 break2 ();
124 flags.uc = 0;
125 flags.u1 = 0;
126 flags.u2 = 0;
127 flags.u3 = 0;
128 flags.u9 = 0;
129
130 flags.s1 = 0x1;
131 flags.s2 = 0x3;
132 flags.s3 = 0x7;
133 flags.s9 = 0x1FF;
134 flags.sc = 0xFF;
135 break2 ();
136 flags.s1 = 0;
137 flags.s2 = 0;
138 flags.s3 = 0;
139 flags.s9 = 0;
140 flags.sc = 0;
141
142 /* Fill the unsigned fields with the maximum positive value and verify
143 that the values are printed correctly. */
144
145 /* Maximum positive values */
146 flags.u1 = 0x1;
147 flags.u2 = 0x3;
148 flags.u3 = 0x7;
149 flags.u9 = 0x1FF;
150 break3 ();
151 flags.u1 = 0;
152 flags.u2 = 0;
153 flags.u3 = 0;
154 flags.u9 = 0;
155
156 /* Fill the signed fields with the maximum positive value, then the maximally
157 negative value, then -1, and verify in each case that the values are
158 printed correctly. */
159
160 /* Maximum positive values */
161 flags.s1 = 0x0;
162 flags.s2 = 0x1;
163 flags.s3 = 0x3;
164 flags.s9 = 0xFF;
165 break4 ();
166
167 /* Maximally negative values */
168 flags.s1 = 0x1;
169 flags.s2 = 0x2;
170 flags.s3 = 0x4;
171 flags.s9 = 0x100;
172 /* Extract bitfield value so that bitfield.exp can check if the target
173 understands signed bitfields. */
174 i = flags.s9;
175 break4 ();
176
177 /* -1 */
178 flags.s1 = 0x1;
179 flags.s2 = 0x3;
180 flags.s3 = 0x7;
181 flags.s9 = 0x1FF;
182 break4 ();
183
184 flags.s1 = 0;
185 flags.s2 = 0;
186 flags.s3 = 0;
187 flags.s9 = 0;
188
189 return 0;
190}
This page took 0.141467 seconds and 4 git commands to generate.