]> git.sur5r.net Git - cc65/blob - test/val/cq88.c
remote TABs in doc/ and test/
[cc65] / test / val / cq88.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 8.8: typedef
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 one(){
47    return 1;
48 }
49 int *metricp;
50 #ifndef NO_OLD_FUNC_DECL
51 s88(pd0)          /*  8.8 Typedef  */
52 struct defs *pd0;
53 {
54 #else
55 int s88(struct defs *pd0){
56 #endif
57    static char s88er[] = "s88,er%d\n";
58    static char qs88[8] = "s88    ";
59    int rc;
60    char *ps, *pt;
61
62         /* Declarations whose "storage class" is typdef do not
63         define storage, but instead define identifiers which
64         can later be used as if they were type keywords naming
65         fundamental or derived types.
66                                                                 */
67
68    typedef int MILES, *KLICKSP;
69
70    #ifndef NO_FLOATS
71    typedef struct {double re, im;} complex;
72    #else
73    typedef struct {signed re, im;} complex;
74    #endif
75
76    MILES distance;
77    #ifndef NO_SLOPPY_EXTERN
78    extern KLICKSP metricp;
79    #else
80    KLICKSP metricp;
81    #endif
82    complex z, *zp;
83
84    ps = qs88;
85    pt = pd0->rfs;
86    rc = 0;
87    while(*pt++ = *ps++);
88
89         /* Hopefully, all of this stuff will compile. After that,
90         we can only make some superficial tests.
91
92         The type of distance is int,
93                                                                 */
94
95    if(sizeof distance != sizeof(int)){
96      if(pd0->flgd != 0) printf(s88er,1);
97      rc = rc+1;
98    }
99
100         /* that of metricp is "pointer to int",                 */
101
102    metricp = &distance;
103    distance = 2;
104    *metricp = 3;
105
106    if(distance != 3){
107      if(pd0->flgd != 0) printf(s88er,2);
108      rc = rc+2;
109    }
110
111         /* and that of z is the specified structure. zp is a
112         pointer to such a structure.
113                                                                 */
114
115    #ifndef NO_FLOATS
116    z.re = 0.;
117    z.im = 0.;
118    zp = &z;
119    zp->re = 1.;
120    zp->im = 1.;
121    if(z.re+z.im != 2.){
122    #else
123    z.re = 0;
124    z.im = 0;
125    zp = &z;
126    zp->re = 1;
127    zp->im = 1;
128    if(z.re+z.im != 2){
129    #endif
130      if(pd0->flgd != 0) printf(s88er,4);
131      rc = rc+4;
132    }
133
134    return rc;
135 }
136
137 /*********************************************************************************************
138  the main loop that launches the sections
139 *********************************************************************************************/
140
141 #ifndef NO_TYPELESS_STRUCT_PTR
142         int section(int j,struct* pd0){
143 #else
144         int section(int j,void* pd0){
145 #endif
146         switch(j){
147                 case 0: return s88(pd0);
148         }
149 }
150
151 #define cq_sections 1
152
153 /*
154         C REFERENCE MANUAL (main)
155 */
156
157 #ifndef NO_OLD_FUNC_DECL
158 main(n,args)
159 int n;
160 char **args;
161 {
162 #else
163 int main(int n,char **args) {
164 #endif
165
166 int j;
167 static struct defs d0, *pd0;
168         
169    d0.flgs = 1;          /* These flags dictate            */
170    d0.flgm = 1;          /*     the verbosity of           */
171    d0.flgd = 1;          /*         the program.           */
172    d0.flgl = 1;
173
174    pd0 = &d0;
175
176    for (j=0; j<cq_sections; j++) {
177      d0.rrc=section(j,pd0);
178      d0.crc=d0.crc+d0.rrc;
179      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
180    }
181
182    if(d0.crc == 0) printf("\nNo errors detected.\n");
183    else printf("\nFailed.\n");
184
185    return d0.crc;
186 }