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