]> git.sur5r.net Git - cc65/blob - test/val/cq84.c
remote TABs in doc/ and test/
[cc65] / test / val / cq84.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 8.4: meaning of declarators
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 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 #ifdef NO_SLOPPY_EXTERN
47    int *fip(int x);
48    int array(int a[],int size,int start);
49    int glork(int x);
50 #endif
51
52 #ifndef NO_OLD_FUNC_DECL
53 s84(pd0)          /*  8.4 Meaning of declarators   */
54 struct defs *pd0;
55 {
56 #else
57 int s84(struct defs *pd0){
58 #endif
59 #ifndef NO_SLOPPY_EXTERN
60    int *ip, i, *fip(), (*pfi)(), j, k, array(), glork();
61 #else
62    int *ip, i, j, k,(*pfi)();
63 /*
64    extern int
65    *fip(),
66    array(),
67    glork();
68    int *fip(int x);
69    int array(int a[],int size,int start);
70 */
71 #endif
72    static int x3d[3][5][7];
73    #ifndef NO_FLOATS
74    float fa[17], *afp[17], sum;
75    #else
76    signed fa[17], *afp[17], sum;
77    #endif
78    static char s84er[] = "s84,er%d\n";
79    static char qs84[8] = "s84    ";
80    int rc;
81    char *ps, *pt;
82    ps = qs84;
83    pt = pd0->rfs;
84    rc = 0;
85    while (*pt++ = *ps++);
86
87         /* The more common varieties of declarators have al-
88         ready been touched upon, some more than others. It
89         is useful to compare *fip() and (*pfi)().
90                                                                 */
91
92    ip = fip(3);
93    if(*ip != 3){
94      if(pd0->flgd != 0) printf(s84er,1);
95      rc = rc+1;
96    }
97
98    /* kludges */
99    #if defined(FORCE_POINTERS) | defined(NO_OLD_FUNC_DECL)
100    if(glork(4) != 4){
101      if(pd0->flgd != 0) printf(s84er,2);
102      rc = rc+2;
103    }
104         #else
105    pfi = glork;
106    if((*pfi)(4) != 4){
107      if(pd0->flgd != 0) printf(s84er,2);
108      rc = rc+2;
109    }
110         #endif
111
112         /* Float fa[17] declares an array of floating point
113         numbers, and *afp[17] declares an array of pointers
114         to floats.
115                                                                 */
116
117    for(j=0; j<17; j++){
118      fa[j] = j;
119      afp[j] = &fa[j];
120    }
121
122    #ifndef NO_FLOATS
123    sum = 0.;
124    #else
125    sum = 0;
126    #endif
127    for(j=0; j<17; j++) sum += *afp[j];
128    if(sum != 136){
129      if(pd0->flgd != 0) printf(s84er,4);
130      rc = rc+4;
131    }
132
133         /*  static int x3d[3][5][7] declares a static three
134         dimensional array of integers, with rank 3x5x7.
135         In complete detail, x3d is an array of three items;
136         each item is an array of five arrays, and each of
137         the latter arrays is an array of seven integers.
138         Any of the expressions x3d, x3d[i], x3d[i][j],
139         and x3d[i][j][k] may reasonably appear in an express-
140         ion. The first three have type "array"; the last has
141         type int.
142                                                                 */
143
144    for (i=0; i<3; i++)
145      for (j=0; j<5; j++)
146        for (k=0; k<7; k++)
147          x3d[i][j][k] = i*35+j*7+k;
148
149    i = 1; j = 2; k = 3;
150
151    /* kludges */
152    #if defined(FORCE_POINTERS) | defined(NO_OLD_FUNC_DECL)
153    if( array((int*)x3d,105,0)
154       +array((int*)x3d[i],35,35)
155    #else
156    if( array(x3d,105,0)
157       +array(x3d[i],35,35)
158    #endif
159       +array(x3d[i][j],7,49)
160       +      x3d[i][j][k]-52){
161       if(pd0->flgd != 0) printf(s84er,8);
162       rc = rc+8;
163    }
164
165    return rc;
166 }
167
168 #ifndef NO_OLD_FUNC_DECL
169 array(a,size,start)
170 int a[],size,start;
171 #else
172 int array(int a[],int size,int start)
173 #endif
174 {
175 /*
176 #ifndef NO_OLD_FUNC_DECL
177 array(a,size,start)
178 int a[],
179 #else
180 int array(int a[],
181 #endif
182 #ifdef NO_TYPELESS_INT
183 int
184 #endif
185 #ifdef NO_TYPELESS_INT
186 int
187 #endif
188
189 #ifndef NO_OLD_FUNC_DECL
190 start; {
191 #else
192 start){
193 #endif
194 */
195    int i;
196    for(i=0; i<size; i++)
197      if(a[i] != i+start) return 1;
198
199    return 0;
200 }
201 #ifndef NO_OLD_FUNC_DECL
202 int *fip(x)
203 int x;
204 {
205 #else
206 int *fip(int x){
207 #endif
208    static int y;
209    y = x;
210    return &y;
211 }
212 #ifndef NO_OLD_FUNC_DECL
213 glork(x)
214 int x;
215 {
216 #else
217 int glork(int x){
218 #endif
219 return x;}
220
221 /*********************************************************************************************
222  the main loop that launches the sections
223 *********************************************************************************************/
224
225 #ifndef NO_TYPELESS_STRUCT_PTR
226         int section(int j,struct* pd0){
227 #else
228         int section(int j,void* pd0){
229 #endif
230         switch(j){
231                 case 0: return s84(pd0);
232         }
233 }
234
235 #define cq_sections 1
236
237 /*
238         C REFERENCE MANUAL (main)
239 */
240
241 #ifndef NO_OLD_FUNC_DECL
242 main(n,args)
243 int n;
244 char **args;
245 {
246 #else
247 int main(int n,char **args) {
248 #endif
249
250 int j;
251 static struct defs d0, *pd0;
252         
253    d0.flgs = 1;          /* These flags dictate            */
254    d0.flgm = 1;          /*     the verbosity of           */
255    d0.flgd = 1;          /*         the program.           */
256    d0.flgl = 1;
257
258    pd0 = &d0;
259
260    for (j=0; j<cq_sections; j++) {
261      d0.rrc=section(j,pd0);
262      d0.crc=d0.crc+d0.rrc;
263      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
264    }
265
266    if(d0.crc == 0) printf("\nNo errors detected.\n");
267    else printf("\nFailed.\n");
268
269    return d0.crc;
270 }