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