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