2 !!DESCRIPTION!! C-Manual Chapter 8.5: Structure and Union declarations
3 !!ORIGIN!! LCC 4.1 Testsuite
4 !!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC
8 int cbits; /* No. of bits per char */
10 int sbits; /* short */
12 int ubits; /* unsigned */
13 int fbits; /* float */
14 int dbits; /* double */
16 float fprec; /* Smallest number that can be */
17 float dprec; /* significantly added to 1. */
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 */
29 int ubits; /* unsigned */
30 int fbits; /* float */
31 int dbits; /* double */
33 float fprec; /* Smallest number that can be */
34 float dprec; /* significantly added to 1. */
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 */
44 #ifndef NO_OLD_FUNC_DECL
45 s85(pd0) /* 8.5 Structure and union declarations */
49 int s85(struct defs *pd0){
51 static char s85er[] = "s85,er%d\n";
52 static char qs85[8] = "s85 ";
63 struct tnode s1, s2, *sp;
110 static char *type[] = {
125 static char aln[] = " alignment: ";
136 unsigned char twobit;
137 unsigned char threebit;
138 unsigned char onebit;
160 while (*pt++ = *ps++);
162 /* Within a structure, the objects declared have
163 addresses which increase as their declarations are
167 if( (char *)&s1.count - &s1.tword[0] <= 0
168 ||(char *)&s1.left - (char *)&s1.count <= 0
169 ||(char *)&s1.right - (char *)&s1.left <= 0){
170 if(pd0->flgd != 0) printf(s85er,1);
174 /* Each non-field member of a structure begins on an
175 addressing boundary appropriate to its type.
178 diff[0] = &sc.c - &sc.cdummy;
179 diff[1] = (char *)&ss.s - &ss.cdummy;
180 diff[2] = (char *)&si.i - &si.cdummy;
181 diff[3] = (char *)&sl.l - &sl.cdummy;
182 diff[4] = (char *)&su.u - &su.cdummy;
183 diff[5] = (char *)&sf.f - &sf.cdummy;
184 diff[6] = (char *)&sd.d - &sd.cdummy;
188 printf("%s%s%d\n",type[j],aln,diff[j]);
190 /* Field specifications are highly implementation de-
191 pendent. About the only thing we can do here is to
192 check is that the compiler accepts the field constructs,
193 and that they seem to work, after a fashion, at
198 s3.twobit = s3.threebit;
199 s3.threebit = s3.twobit;
201 if(s3.threebit != 3){
202 if(s3.threebit == -1){
203 if(pd0->flgm != 0) printf("Sign extension in fields\n");
207 if(pd0->flgd != 0) printf("NO_BITFIELDS\n");
209 if(pd0->flgd != 0) printf(s85er,2);
218 printf("Be especially careful with 1-bit fields!\n");
221 /* A union may be thought of as a structure all of whose
222 members begin at offset 0 and whose size is sufficient
223 to contain any of its members.
226 if( (char *)u0.u1 - (char *)&u0 != 0
227 ||(char *)u0.u2 - (char *)&u0 != 0
228 ||(char *)u0.u3 - (char *)&u0 != 0
229 ||(char *)u0.u4 - (char *)&u0 != 0
230 ||(char *)u0.u5 - (char *)&u0 != 0
231 ||(char *)u0.u6 - (char *)&u0 != 0
232 ||(char *)u0.u7 - (char *)&u0 != 0){
233 if(pd0->flgd != 0) printf(s85er,4);
237 if( sizeof u0 < sizeof u0.u1
238 ||sizeof u0 < sizeof u0.u2
239 ||sizeof u0 < sizeof u0.u3
240 ||sizeof u0 < sizeof u0.u4
241 ||sizeof u0 < sizeof u0.u5
242 ||sizeof u0 < sizeof u0.u6
243 ||sizeof u0 < sizeof u0.u7){
244 if(pd0->flgd != 0) printf(s85er,8);
248 /* Finally, we check that the pointers work. */
252 s1.right->tword[0] += 1;
253 if(s2.tword[0] != 3){
254 if(pd0->flgd != 0) printf(s85er,16);
260 #ifdef NO_LOCAL_PROTOTYPES
264 /*********************************************************************************************
265 the main loop that launches the sections
266 *********************************************************************************************/
268 #ifndef NO_TYPELESS_STRUCT_PTR
269 int section(int j,struct* pd0){
271 int section(int j,void* pd0){
274 case 0: return s85(pd0);
278 #define cq_sections 1
281 C REFERENCE MANUAL (main)
284 #ifndef NO_OLD_FUNC_DECL
290 int main(int n,char **args) {
294 static struct defs d0, *pd0;
296 d0.flgs = 1; /* These flags dictate */
297 d0.flgm = 1; /* the verbosity of */
298 d0.flgd = 1; /* the program. */
303 for (j=0; j<cq_sections; j++) {
304 d0.rrc=section(j,pd0);
305 d0.crc=d0.crc+d0.rrc;
306 if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
309 if(d0.crc == 0) printf("\nNo errors detected.\n");
310 else printf("\nFailed.\n");