2 !!DESCRIPTION!! C-Manual Chapter 7.8: Bitwise AND operator, 7.9 Bitwise OR operator, 7.10 Bitwise exclusive OR operator, 7.11 Logical AND operator, 7.12 Logical OR operator, 7.13 Conditional operator
3 !!ORIGIN!! LCC 4.1 Testsuite
4 !!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC
10 int cbits; /* No. of bits per char */
12 int sbits; /* short */
14 int ubits; /* unsigned */
15 int fbits; /* float */
16 int dbits; /* double */
18 float fprec; /* Smallest number that can be */
19 float dprec; /* significantly added to 1. */
21 int flgs; /* Print return codes, by section */
22 int flgm; /* Announce machine dependencies */
23 int flgd; /* give explicit diagnostics */
24 int flgl; /* Report local return codes. */
25 int rrc; /* recent return code */
26 int crc; /* Cumulative return code */
27 char rfs[8]; /* Return from section */
31 int ubits; /* unsigned */
32 int fbits; /* float */
33 int dbits; /* double */
35 float fprec; /* Smallest number that can be */
36 float dprec; /* significantly added to 1. */
38 int flgs; /* Print return codes, by section */
39 int flgm; /* Announce machine dependencies */
40 int flgd; /* give explicit diagnostics */
41 int flgl; /* Report local return codes. */
42 int rrc; /* recent return code */
43 int crc; /* Cumulative return code */
44 char rfs[8]; /* Return from section */
46 #ifndef NO_OLD_FUNC_DECL
47 s7813(pd0) /* 7.8 Bitwise AND operator
48 7.9 Bitwise OR operator
49 7.10 Bitwise exclusive OR operator
50 7.11 Logical AND operator
51 7.12 Logical OR operator
52 7.13 Conditional operator */
56 int s7813(struct defs *pd0){
58 register int prlc, lrc;
59 int i, j, r, zero, one;
60 static char fl[] = "Local error %d.\n";
61 static char s7813er[] = "s7813,er%d\n";
62 static char qs7813[8] = "s7813 ";
70 while (*pt++ = *ps++);
72 /* If bitwise AND, OR, and exclusive OR are to cause
73 trouble, they will probably do so when they are used in
74 an unusual context. The number of contexts in which
75 they can be used is infinite, so to save time we select
76 a finite subset: the set of all expressions of the form:
80 where item1 and item2 are chosen from the set
81 {char,short,long,unsigned,int} and op is one of {&,|,^}.
82 We will use 12 and 10 as values for the items, as these
83 values will fit into all data types on just about any
84 imaginable machine, and the results after performing the
85 bitwise operations on them are distinct for each operation,
88 12 | 10 -> 1100 | 1010 -> 1110 -> 14
89 12 ^ 10 -> 1100 ^ 1010 -> 0110 -> 6
90 12 & 10 -> 1100 & 1010 -> 1000 -> 8
92 There are 75 such combinations:
95 if(((char)12 & (char)10) != 8) {lrc = 1;
96 if(prlc) printf(fl,lrc);}
97 if(((char)12 | (char)10) != 14) {lrc = 2;
98 if(prlc) printf(fl,lrc);}
99 if(((char)12 ^ (char)10) != 6) {lrc = 3;
100 if(prlc) printf(fl,lrc);}
101 if(((char)12 & (short)10) != 8) {lrc = 4;
102 if(prlc) printf(fl,lrc);}
103 if(((char)12 | (short)10) != 14) {lrc = 5;
104 if(prlc) printf(fl,lrc);}
105 if(((char)12 ^ (short)10) != 6) {lrc = 6;
106 if(prlc) printf(fl,lrc);}
107 if(((char)12 & (long)10) != 8) {lrc = 7;
108 if(prlc) printf(fl,lrc);}
109 if(((char)12 | (long)10) != 14) {lrc = 8;
110 if(prlc) printf(fl,lrc);}
111 if(((char)12 ^ (long)10) != 6) {lrc = 9;
112 if(prlc) printf(fl,lrc);}
113 if(((char)12 & (unsigned)10) != 8) {lrc = 10;
114 if(prlc) printf(fl,lrc);}
115 if(((char)12 | (unsigned)10) != 14) {lrc = 11;
116 if(prlc) printf(fl,lrc);}
117 if(((char)12 ^ (unsigned)10) != 6) {lrc = 12;
118 if(prlc) printf(fl,lrc);}
119 if(((char)12 & (int)10) != 8) {lrc = 13;
120 if(prlc) printf(fl,lrc);}
121 if(((char)12 | (int)10) != 14) {lrc = 14;
122 if(prlc) printf(fl,lrc);}
123 if(((char)12 ^ (int)10) != 6) {lrc = 15;
124 if(prlc) printf(fl,lrc);}
125 if(((short)12 & (char)10) != 8) {lrc = 16;
126 if(prlc) printf(fl,lrc);}
127 if(((short)12 | (char)10) != 14) {lrc = 17;
128 if(prlc) printf(fl,lrc);}
129 if(((short)12 ^ (char)10) != 6) {lrc = 18;
130 if(prlc) printf(fl,lrc);}
131 if(((short)12 & (short)10) != 8) {lrc = 16;
132 if(prlc) printf(fl,lrc);}
133 if(((short)12 | (short)10) != 14) {lrc = 20;
134 if(prlc) printf(fl,lrc);}
135 if(((short)12 ^ (short)10) != 6) {lrc = 21;
136 if(prlc) printf(fl,lrc);}
137 if(((short)12 & (long)10) != 8) {lrc = 22;
138 if(prlc) printf(fl,lrc);}
139 if(((short)12 | (long)10) != 14) {lrc = 23;
140 if(prlc) printf(fl,lrc);}
141 if(((short)12 ^ (long)10) != 6) {lrc = 24;
142 if(prlc) printf(fl,lrc);}
143 if(((short)12 & (unsigned)10) != 8) {lrc = 25;
144 if(prlc) printf(fl,lrc);}
145 if(((short)12 | (unsigned)10) != 14) {lrc = 26;
146 if(prlc) printf(fl,lrc);}
147 if(((short)12 ^ (unsigned)10) != 6) {lrc = 27;
148 if(prlc) printf(fl,lrc);}
149 if(((short)12 & (int)10) != 8) {lrc = 28;
150 if(prlc) printf(fl,lrc);}
151 if(((short)12 | (int)10) != 14) {lrc = 26;
152 if(prlc) printf(fl,lrc);}
153 if(((short)12 ^ (int)10) != 6) {lrc = 30;
154 if(prlc) printf(fl,lrc);}
155 if(((long)12 & (char)10) != 8) {lrc = 31;
156 if(prlc) printf(fl,lrc);}
157 if(((long)12 | (char)10) != 14) {lrc = 32;
158 if(prlc) printf(fl,lrc);}
159 if(((long)12 ^ (char)10) != 6) {lrc = 33;
160 if(prlc) printf(fl,lrc);}
161 if(((long)12 & (short)10) != 8) {lrc = 34;
162 if(prlc) printf(fl,lrc);}
163 if(((long)12 | (short)10) != 14) {lrc = 35;
164 if(prlc) printf(fl,lrc);}
165 if(((long)12 ^ (short)10) != 6) {lrc = 36;
166 if(prlc) printf(fl,lrc);}
167 if(((long)12 & (long)10) != 8) {lrc = 37;
168 if(prlc) printf(fl,lrc);}
169 if(((long)12 | (long)10) != 14) {lrc = 38;
170 if(prlc) printf(fl,lrc);}
171 if(((long)12 ^ (long)10) != 6) {lrc = 39;
172 if(prlc) printf(fl,lrc);}
173 if(((long)12 & (unsigned)10) != 8) {lrc = 40;
174 if(prlc) printf(fl,lrc);}
175 if(((long)12 | (unsigned)10) != 14) {lrc = 41;
176 if(prlc) printf(fl,lrc);}
177 if(((long)12 ^ (unsigned)10) != 6) {lrc = 42;
178 if(prlc) printf(fl,lrc);}
179 if(((long)12 & (int)10) != 8) {lrc = 43;
180 if(prlc) printf(fl,lrc);}
181 if(((long)12 | (int)10) != 14) {lrc = 44;
182 if(prlc) printf(fl,lrc);}
183 if(((long)12 ^ (int)10) != 6) {lrc = 45;
184 if(prlc) printf(fl,lrc);}
185 if(((unsigned)12 & (char)10) != 8) {lrc = 46;
186 if(prlc) printf(fl,lrc);}
187 if(((unsigned)12 | (char)10) != 14) {lrc = 47;
188 if(prlc) printf(fl,lrc);}
189 if(((unsigned)12 ^ (char)10) != 6) {lrc = 48;
190 if(prlc) printf(fl,lrc);}
191 if(((unsigned)12 & (short)10) != 8) {lrc = 49;
192 if(prlc) printf(fl,lrc);}
193 if(((unsigned)12 | (short)10) != 14) {lrc = 50;
194 if(prlc) printf(fl,lrc);}
195 if(((unsigned)12 ^ (short)10) != 6) {lrc = 51;
196 if(prlc) printf(fl,lrc);}
197 if(((unsigned)12 & (long)10) != 8) {lrc = 52;
198 if(prlc) printf(fl,lrc);}
199 if(((unsigned)12 | (long)10) != 14) {lrc = 53;
200 if(prlc) printf(fl,lrc);}
201 if(((unsigned)12 ^ (long)10) != 6) {lrc = 54;
202 if(prlc) printf(fl,lrc);}
203 if(((unsigned)12 & (unsigned)10) != 8) {lrc = 55;
204 if(prlc) printf(fl,lrc);}
205 if(((unsigned)12 | (unsigned)10) != 14) {lrc = 56;
206 if(prlc) printf(fl,lrc);}
207 if(((unsigned)12 ^ (unsigned)10) != 6) {lrc = 57;
208 if(prlc) printf(fl,lrc);}
209 if(((unsigned)12 & (int)10) != 8) {lrc = 58;
210 if(prlc) printf(fl,lrc);}
211 if(((unsigned)12 | (int)10) != 14) {lrc = 56;
212 if(prlc) printf(fl,lrc);}
213 if(((unsigned)12 ^ (int)10) != 6) {lrc = 60;
214 if(prlc) printf(fl,lrc);}
215 if(((int)12 & (char)10) != 8) {lrc = 61;
216 if(prlc) printf(fl,lrc);}
217 if(((int)12 | (char)10) != 14) {lrc = 62;
218 if(prlc) printf(fl,lrc);}
219 if(((int)12 ^ (char)10) != 6) {lrc = 63;
220 if(prlc) printf(fl,lrc);}
221 if(((int)12 & (short)10) != 8) {lrc = 64;
222 if(prlc) printf(fl,lrc);}
223 if(((int)12 | (short)10) != 14) {lrc = 65;
224 if(prlc) printf(fl,lrc);}
225 if(((int)12 ^ (short)10) != 6) {lrc = 66;
226 if(prlc) printf(fl,lrc);}
227 if(((int)12 & (long)10) != 8) {lrc = 67;
228 if(prlc) printf(fl,lrc);}
229 if(((int)12 | (long)10) != 14) {lrc = 68;
230 if(prlc) printf(fl,lrc);}
231 if(((int)12 ^ (long)10) != 6) {lrc = 69;
232 if(prlc) printf(fl,lrc);}
233 if(((int)12 & (unsigned)10) != 8) {lrc = 70;
234 if(prlc) printf(fl,lrc);}
235 if(((int)12 | (unsigned)10) != 14) {lrc = 71;
236 if(prlc) printf(fl,lrc);}
237 if(((int)12 ^ (unsigned)10) != 6) {lrc = 72;
238 if(prlc) printf(fl,lrc);}
239 if(((int)12 & (int)10) != 8) {lrc = 73; if(prlc) printf(fl,lrc);}
240 if(((int)12 | (int)10) != 14) {lrc = 74; if(prlc) printf(fl,lrc);}
241 if(((int)12 ^ (int)10) != 6) {lrc = 75; if(prlc) printf(fl,lrc);}
244 if(pd0->flgd != 0) printf(s7813er,1);
248 /* The && operator groups left to right. It returns 1
249 if both of the operands are nonzero; 0 otherwise.
250 It guarantees left to right evaluation; moreover, the
251 second operand is not evaluated if the value of the
259 if(i!=1) {lrc = 1; if(prlc) printf(fl,lrc);}
260 if(j!=0) {lrc = 2; if(prlc) printf(fl,lrc);}
261 if(r!=0) {lrc = 3; if(prlc) printf(fl,lrc);}
263 if(i!=1) {lrc = 4; if(prlc) printf(fl,lrc);}
264 if(j!=1) {lrc = 5; if(prlc) printf(fl,lrc);}
265 if(r!=0) {lrc = 6; if(prlc) printf(fl,lrc);}
267 if(i!=0) {lrc = 7; if(prlc) printf(fl,lrc);}
268 if(j!=1) {lrc = 8; if(prlc) printf(fl,lrc);}
269 if(r!=1) {lrc = 9; if(prlc) printf(fl,lrc);}
271 if(i!=0) {lrc = 10; if(prlc) printf(fl,lrc);}
272 if(j!=1) {lrc = 11; if(prlc) printf(fl,lrc);}
273 if(r!=0) {lrc = 12; if(prlc) printf(fl,lrc);}
276 if(pd0->flgd != 0) printf(s7813er,2);
280 /* The || operator groups left to right. It returns 1
281 if either of its operands is nonzero; 0 otherwise. It
282 guarantees left to right evaluation; moreover, the second
283 operand is not evaluated if the value of the first
290 if(i!=1) {lrc = 1; if(prlc) printf(fl,lrc);}
291 if(j!=0) {lrc = 2; if(prlc) printf(fl,lrc);}
292 if(r!=0) {lrc = 3; if(prlc) printf(fl,lrc);}
294 if(i!=1) {lrc = 4; if(prlc) printf(fl,lrc);}
295 if(j!=1) {lrc = 5; if(prlc) printf(fl,lrc);}
296 if(r!=1) {lrc = 6; if(prlc) printf(fl,lrc);}
298 if(i!=0) {lrc = 7; if(prlc) printf(fl,lrc);}
299 if(j!=1) {lrc = 8; if(prlc) printf(fl,lrc);}
300 if(r!=1) {lrc = 9; if(prlc) printf(fl,lrc);}
302 if(i!=0) {lrc = 10; if(prlc) printf(fl,lrc);}
303 if(j!=0) {lrc = 11; if(prlc) printf(fl,lrc);}
304 if(r!=1) {lrc = 12; if(prlc) printf(fl,lrc);}
307 if(pd0->flgd != 0) printf(s7813er,4);
311 /* Conditional expressions group right to left. */
316 r = one?zero:one?i++:j++;
317 if(r!=0 || i!=0 || j!=0){
318 if(pd0->flgd != 0) printf(s7813er,8);
322 /* The first expression is evaluated and if it is non-
323 zero, the result is the value of the second expression;
324 otherwise, that of the third expression.
327 if((one?zero:1) != 0 || (zero?1:zero) != 0){
328 if(pd0->flgd != 0) printf(s7813er,16);
334 /*********************************************************************************************
335 the main loop that launches the sections
336 *********************************************************************************************/
338 #ifndef NO_TYPELESS_STRUCT_PTR
339 int section(int j,struct* pd0){
341 int section(int j,void* pd0){
344 case 0: return s7813(pd0);
348 #define cq_sections 1
351 C REFERENCE MANUAL (main)
354 #ifndef NO_OLD_FUNC_DECL
360 int main(int n,char **args) {
364 static struct defs d0, *pd0;
366 d0.flgs = 1; /* These flags dictate */
367 d0.flgm = 1; /* the verbosity of */
368 d0.flgd = 1; /* the program. */
373 for (j=0; j<cq_sections; j++) {
374 d0.rrc=section(j,pd0);
375 d0.crc=d0.crc+d0.rrc;
376 if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
379 if(d0.crc == 0) printf("\nNo errors detected.\n");
380 else printf("\nFailed.\n");