]> git.sur5r.net Git - cc65/blob - test/val/cq86.c
added tests as prepared by oliver
[cc65] / test / val / cq86.c
1 /*
2   !!DESCRIPTION!! C-Manual Chapter 8.6: Initialization
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 #ifdef NO_LOCAL_PROTOTYPES
45 int one();
46 #endif
47
48 #ifndef NO_OLD_FUNC_DECL
49 s86(pd0)          /*  8.6 Initialization  */
50 struct defs *pd0;
51 {
52 #else
53 int s86(struct defs *pd0){
54 #endif
55    static char s86er[] = "s86,er%d\n";
56    static char qs86[8] = "s86    ";
57    int lrc, rc;
58    char *ps, *pt;
59    #ifndef NO_LOCAL_PROTOTYPES
60    int one();
61    #endif
62    int i, j, k;
63    static int x[] = {1,3,5};
64    static int *pint = x+2;
65    static int zero[10];
66    int *apint = pint-1;
67    register int *rpint = apint+one();
68
69    #ifndef NO_FLOATS
70    static float y0[] = {1,3,5,2,4,6,3,5,7,0,0,0};
71    static float y1[4][3] = {
72      {1,3,5},
73      {2,4,6},
74      {3,5,7},
75    };
76    static float y2[4][3] = {1,3,5,2,4,6,3,5,7};
77    static float y3[4][3] = {
78      {1},{2},{3},{4}
79    };
80    #else
81    static signed y0[] = {1,3,5,2,4,6,3,5,7,0,0,0};
82    static signed y1[4][3] = {
83      {1,3,5},
84      {2,4,6},
85      {3,5,7},
86    };
87    #ifndef NO_SLOPPY_STRUCT_INIT
88    static signed y2[4][3] = {1,3,5,2,4,6,3,5,7};
89    #else
90    static signed y2[4][3] = {{1,3,5},{2,4,6},{3,5,7}};
91    #endif
92    static signed y3[4][3] = {
93      {1},{2},{3},{4}
94    };
95    #endif
96
97    ps = qs86;
98    pt = pd0->rfs;
99    rc = 0;
100    while (*pt++ = *ps++);
101
102         /* The expression in an initializer for a static or
103         external variable must be a constant expression or
104         an expression that reduces to the address of a pre-
105         viously declared variable, possibly offset by a
106         constant expression.
107                                                                 */
108
109    if(*pint != 5){
110      if(pd0->flgd != 0) printf(s86er,1);
111      rc = rc+1;
112    }
113
114         /* Automatic and register variables may be initialized
115         by arbitrary expressions involving constants and previously
116         declared variables and functions.
117                                                                 */
118
119    if(*apint != 3){
120      if(pd0->flgd != 0) printf(s86er,2);
121      rc = rc+2;
122    }
123
124    if(*rpint != 5){
125      if(pd0->flgd != 0) printf(s86er,4);
126      rc = rc+4;
127    }
128
129         /* Static variables that are not initialized are guar-
130         anteed to start off as zero.
131                                                         */
132
133    lrc = 0;
134    for(j=0; j<10; j++)
135      if(zero[j] != 0) lrc = 1;
136    if(lrc != 0){
137      if(pd0->flgd != 0) printf(s86er,8);
138      rc = rc+8;
139    }
140
141         /* y0, y1, and y2, as declared, should define and
142         initialize identical arrays.
143                                                                 */
144    lrc = 0;
145    for(i=0; i<4; i++)
146      for(j=0; j<3; j++){
147        k = 3*i+j;
148        if( y1[i][j] != y2[i][j]
149          ||y1[i][j] != y0[k]) lrc = 1;
150      }
151
152    if(lrc != 0){
153      if(pd0->flgd != 0) printf(s86er,16);
154      rc = rc+16;
155    }
156
157         /* y3 initializes the first column of the array and
158         leaves the rest zero.
159                                                                 */
160
161    lrc = 0;
162    for(j=0; j<4; j++) if(y3[j][0] != j+1) lrc = 1;
163
164    if(lrc != 0){
165      if(pd0->flgd != 0) printf(s86er,32);
166      rc = rc+32;
167    }
168    return rc;
169 }
170 #ifndef NO_OLD_FUNC_DECL
171 one(){
172 #else
173 int one(){
174 #endif
175    return 1;
176 }
177 int *metricp;
178
179 /*********************************************************************************************
180  the main loop that launches the sections
181 *********************************************************************************************/
182
183 #ifndef NO_TYPELESS_STRUCT_PTR
184         int section(int j,struct* pd0){
185 #else
186         int section(int j,void* pd0){
187 #endif
188         switch(j){
189                 case 0: return s86(pd0);
190         }
191 }
192
193 #define cq_sections 1
194
195 /*
196         C REFERENCE MANUAL (main)
197 */
198
199 #ifndef NO_OLD_FUNC_DECL
200 main(n,args)
201 int n;
202 char **args;
203 {
204 #else
205 int main(int n,char **args) {
206 #endif
207
208 int j;
209 static struct defs d0, *pd0;
210         
211    d0.flgs = 1;          /* These flags dictate            */
212    d0.flgm = 1;          /*     the verbosity of           */
213    d0.flgd = 1;          /*         the program.           */
214    d0.flgl = 1;
215
216    pd0 = &d0;
217
218    for (j=0; j<cq_sections; j++) {
219      d0.rrc=section(j,pd0);
220      d0.crc=d0.crc+d0.rrc;
221      if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
222    }
223
224    if(d0.crc == 0) printf("\nNo errors detected.\n");
225    else printf("\nFailed.\n");
226
227    return d0.crc;
228 }