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