]> git.sur5r.net Git - cc65/blob - test/val/cq71.c
remote TABs in doc/ and test/
[cc65] / test / val / cq71.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 7.1: primary expressions
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 /*include "cq26.c"*/ /* hardware check */
10
11 struct defs {
12      int cbits;          /* No. of bits per char           */
13      int ibits;          /*                 int            */
14      int sbits;          /*                 short          */
15      int lbits;          /*                 long           */
16      int ubits;          /*                 unsigned       */
17      int fbits;          /*                 float          */
18      int dbits;          /*                 double         */
19      #ifndef NO_FLOATS
20         float fprec;        /* Smallest number that can be    */
21         float dprec;        /* significantly added to 1.      */
22      #endif
23      int flgs;           /* Print return codes, by section */
24      int flgm;           /* Announce machine dependencies  */
25      int flgd;           /* give explicit diagnostics      */
26      int flgl;           /* Report local return codes.     */
27      int rrc;            /* recent return code             */
28      int crc;            /* Cumulative return code         */
29      char rfs[8];        /* Return from section            */
30 };
31
32      int lbits;          /*                 long           */
33      int ubits;          /*                 unsigned       */
34      int fbits;          /*                 float          */
35      int dbits;          /*                 double         */
36      #ifndef NO_FLOATS
37         float fprec;        /* Smallest number that can be    */
38         float dprec;        /* significantly added to 1.      */
39      #endif
40      int flgs;           /* Print return codes, by section */
41      int flgm;           /* Announce machine dependencies  */
42      int flgd;           /* give explicit diagnostics      */
43      int flgl;           /* Report local return codes.     */
44      int rrc;            /* recent return code             */
45      int crc;            /* Cumulative return code         */
46      char rfs[8];        /* Return from section            */
47
48 int extvar;
49
50 #ifndef NO_OLD_FUNC_DECL
51 s71(pd0)          /*         7.1  Primary expressions   */
52 struct defs *pd0;
53 {
54 #else
55 int s71(struct defs *pd0){
56 #endif
57    static char s71er[] = "s71,er%d\n";
58    static char qs71[8] = "s71    ";
59    int rc;
60    char *ps, *pt;
61    static char q = 'q';
62 #ifndef NO_SLOPPY_EXTERN
63    int x[10], McCarthy(), clobber(), a, b, *p;
64 #else
65    int x[10], a, b, *p;
66 #endif
67    ps = qs71;
68    pt = pd0->rfs;
69    rc = 0;
70    while (*pt++ = *ps++);
71
72 /*   Testing of expressions and operators is quite complicated,
73      because (a) problems are apt to surface in queer combinations
74      of operators and operands, rather than in isolation,
75      and (b) the number of expressions needed to provoke a case
76      of improper behaviour may be quite large. Hence, we take the
77      following approach: for this section, and for subsequent
78      sections through 7.15, we will check the primitive operations
79      in isolation, thus verifying that the primitives work,
80      after a fashion. The job of testing combinations, we will
81      leave to a separate, machine-generated program, to be included
82      in the C test package at some later date.
83                                                                 */
84
85 /*   A string is a primary expression. The identifier points to
86      the first character of a string.
87                                                                   */
88
89    if(*"queep" != q){
90      rc = rc+1;
91      if(pd0->flgd  != 0) printf(s71er,1);
92    }
93 /*   A parenthesized expression is a primary expression whose
94      type and value are the same as those of the unadorned
95      expression.
96                                                                 */
97    if((2+3) != 2+3) {
98      rc = rc+2;
99      if(pd0->flgd != 0) printf(s71er,2);
100    }
101
102 /*   A primary expression followed by an expression in square
103      brackets is a primary expression. The intuitive meaning is
104      that of a subscript. The expression E1[E2] is identical
105      (by definition) to *((E1)+(E2)).
106                                                                 */
107
108    x[5] = 1942;
109    if(x[5] != 1942 || x[5] != *((x)+(5))){
110      rc = rc+4;
111      if(pd0->flgd != 0) printf(s71er,4);
112    }
113
114 /*   If the various flavors of function calls didn't work, we
115      would never have gotten this far; however, we do need to
116      show that functions can be recursive...
117                                                                */
118
119    if ( McCarthy(-5) != 91){
120      rc = rc+8;
121      if(pd0->flgd != 0) printf(s71er,8);
122    }
123
124 /*   and that argument passing is strictly by value.           */
125
126    a = 2;
127    b = 3;
128    p = &b;
129
130    clobber(a,p);
131
132    if(a != 2 || b != 2){
133      rc = rc+16;
134      if(pd0->flgd != 0) printf(s71er,16);
135    }
136
137 /*   Finally, structures and unions are addressed thusly:      */
138
139    #ifndef NO_FLOATS
140
141    if(pd0->dprec != (*pd0).dprec){
142      rc = rc+32;
143      if(pd0->flgd != 0) printf(s71er,32);
144    }
145
146    #endif
147
148    return rc;
149 }
150 #ifndef NO_OLD_FUNC_DECL
151 McCarthy(x)
152 int x;
153 {
154 #else
155 int McCarthy(int x){
156 #endif
157    if(x>100) return x-10;
158    else return McCarthy( McCarthy(x+11));
159 }
160
161 #ifndef NO_OLD_FUNC_DECL
162 clobber(x,y)
163 int x,*y;
164 #else
165 int clobber(int x,int *y)
166 #endif
167
168 /*
169 #ifndef NO_OLD_FUNC_DECL
170 clobber(x,y)
171 int x,
172 #ifdef NO_TYPELESS_INT_PTR
173 int
174 #endif
175 *y;
176 {
177 #else
178 int clobber(int x,
179 #ifdef NO_TYPELESS_INT_PTR
180 int
181 #endif
182 *y
183 ){
184 #endif
185 */
186
187 {
188    x = 3;
189    *y = 2;
190 }
191
192 /*********************************************************************************************
193  the main loop that launches the sections
194 *********************************************************************************************/
195
196 #ifndef NO_TYPELESS_STRUCT_PTR
197         int section(int j,struct* pd0){
198 #else
199         int section(int j,void* pd0){
200 #endif
201         switch(j){
202                 /*case 0: return s26(pd0);*/
203                 case 0: return s71(pd0);
204         }
205 }
206
207 #define cq_sections 1
208
209 /*
210         C REFERENCE MANUAL (main)
211 */
212
213 #ifndef NO_OLD_FUNC_DECL
214 main(n,args)
215 int n;
216 char **args;
217 {
218 #else
219 int main(int n,char **args) {
220 #endif
221
222 int j;
223 static struct defs d0, *pd0;
224         
225    d0.flgs = 1;          /* These flags dictate            */
226    d0.flgm = 1;          /*     the verbosity of           */
227    d0.flgd = 1;          /*         the program.           */
228    d0.flgl = 1;
229
230    pd0 = &d0;
231
232    for (j=0; j<cq_sections; j++) {
233      d0.rrc=section(j,pd0);
234      d0.crc=d0.crc+d0.rrc;
235      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
236    }
237
238    if(d0.crc == 0) printf("\nNo errors detected.\n");
239    else printf("\nFailed.\n");
240
241    return d0.crc;
242 }