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
10 int cbits; /* No. of bits per char */
12 int sbits; /* short */
14 int ubits; /* unsigned */
15 int fbits; /* float */
16 int dbits; /* double */
18 float fprec; /* Smallest number that can be */
19 float dprec; /* significantly added to 1. */
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 */
31 int ubits; /* unsigned */
32 int fbits; /* float */
33 int dbits; /* double */
35 float fprec; /* Smallest number that can be */
36 float dprec; /* significantly added to 1. */
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 */
46 #ifndef NO_OLD_FUNC_DECL
47 s85(pd0) /* 8.5 Structure and union declarations */
51 int s85(struct defs *pd0){
53 static char s85er[] = "s85,er%d\n";
54 static char qs85[8] = "s85 ";
65 struct tnode s1, s2, *sp;
112 static char *type[] = {
127 static char aln[] = " alignment: ";
138 unsigned char twobit;
139 unsigned char threebit;
140 unsigned char onebit;
162 while (*pt++ = *ps++);
164 /* Within a structure, the objects declared have
165 addresses which increase as their declarations are
169 if( (char *)&s1.count - &s1.tword[0] <= 0
170 ||(char *)&s1.left - (char *)&s1.count <= 0
171 ||(char *)&s1.right - (char *)&s1.left <= 0){
172 if(pd0->flgd != 0) printf(s85er,1);
176 /* Each non-field member of a structure begins on an
177 addressing boundary appropriate to its type.
180 diff[0] = &sc.c - &sc.cdummy;
181 diff[1] = (char *)&ss.s - &ss.cdummy;
182 diff[2] = (char *)&si.i - &si.cdummy;
183 diff[3] = (char *)&sl.l - &sl.cdummy;
184 diff[4] = (char *)&su.u - &su.cdummy;
185 diff[5] = (char *)&sf.f - &sf.cdummy;
186 diff[6] = (char *)&sd.d - &sd.cdummy;
190 printf("%s%s%d\n",type[j],aln,diff[j]);
192 /* Field specifications are highly implementation de-
193 pendent. About the only thing we can do here is to
194 check is that the compiler accepts the field constructs,
195 and that they seem to work, after a fashion, at
200 s3.twobit = s3.threebit;
201 s3.threebit = s3.twobit;
203 if(s3.threebit != 3){
204 if(s3.threebit == -1){
205 if(pd0->flgm != 0) printf("Sign extension in fields\n");
209 if(pd0->flgd != 0) printf("NO_BITFIELDS\n");
211 if(pd0->flgd != 0) printf(s85er,2);
220 printf("Be especially careful with 1-bit fields!\n");
223 /* A union may be thought of as a structure all of whose
224 members begin at offset 0 and whose size is sufficient
225 to contain any of its members.
228 if( (char *)u0.u1 - (char *)&u0 != 0
229 ||(char *)u0.u2 - (char *)&u0 != 0
230 ||(char *)u0.u3 - (char *)&u0 != 0
231 ||(char *)u0.u4 - (char *)&u0 != 0
232 ||(char *)u0.u5 - (char *)&u0 != 0
233 ||(char *)u0.u6 - (char *)&u0 != 0
234 ||(char *)u0.u7 - (char *)&u0 != 0){
235 if(pd0->flgd != 0) printf(s85er,4);
239 if( sizeof u0 < sizeof u0.u1
240 ||sizeof u0 < sizeof u0.u2
241 ||sizeof u0 < sizeof u0.u3
242 ||sizeof u0 < sizeof u0.u4
243 ||sizeof u0 < sizeof u0.u5
244 ||sizeof u0 < sizeof u0.u6
245 ||sizeof u0 < sizeof u0.u7){
246 if(pd0->flgd != 0) printf(s85er,8);
250 /* Finally, we check that the pointers work. */
254 s1.right->tword[0] += 1;
255 if(s2.tword[0] != 3){
256 if(pd0->flgd != 0) printf(s85er,16);
262 #ifdef NO_LOCAL_PROTOTYPES
266 /*********************************************************************************************
267 the main loop that launches the sections
268 *********************************************************************************************/
270 #ifndef NO_TYPELESS_STRUCT_PTR
271 int section(int j,struct* pd0){
273 int section(int j,void* pd0){
276 case 0: return s85(pd0);
280 #define cq_sections 1
283 C REFERENCE MANUAL (main)
286 #ifndef NO_OLD_FUNC_DECL
292 int main(int n,char **args) {
296 static struct defs d0, *pd0;
298 d0.flgs = 1; /* These flags dictate */
299 d0.flgm = 1; /* the verbosity of */
300 d0.flgd = 1; /* the program. */
305 for (j=0; j<cq_sections; j++) {
306 d0.rrc=section(j,pd0);
307 d0.crc=d0.crc+d0.rrc;
308 if(d0.flgs != 0) printf("Section %s returned %d.\n",d0.rfs,d0.rrc);
311 if(d0.crc == 0) printf("\nNo errors detected.\n");
312 else printf("\nFailed.\n");