Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC830713); site edai.UUCP Path: utzoo!watmath!clyde!floyd!vax135!ukc!edcaad!edee!edai!ok From: ok@edai.UUCP (Richard O'Keefe) Newsgroups: net.lang.c Subject: 'struct' - declarations & parameters Message-ID: <4033@edai.UUCP> Date: Thu, 16-Feb-84 16:25:58 EST Article-I.D.: edai.4033 Posted: Thu Feb 16 16:25:58 1984 Date-Received: Mon, 20-Feb-84 09:14:58 EST Organization: Art.Intelligence,Edin.Univ. Lines: 69 A couple of days ago I had occasion to port a large C program from a VAX to an Orion. The C compiler on the Orion was not based on the PCC but was derived directly from the book and the V7 addendum, then hacked until all the 4.1bsd programs were correctly compiled. A note and a question. The note is that they have two stacks (like the C machine and the RISC chip) : one for scalars and one for arrays. 'struct' arguments are passed on the array stack, and struct values returned there. I can find nothing in the rather sketchy descriptions of C available to forbid this. Consequently, struct {int a, b, c;} foo = {1, 2, 3}; main () { printf("%d %d %d\n", foo); } which works just fine on a VAX, doesn't work on an Orion. I suspect that it may not work on a RISC chip or on a C70 either. Not only are structs passed on the array stack. So are unions. I found out the hard way on the VAX that even when a union fits into 32 bits the PCC still treats it as a "big" object, so the Orion C compiler is not alone in treating unions differently from integers etc. The result of that is that char xc = 12, *pc = &xc; double xd = 19.7, *pd = &xd; void bother(x, i) union {char *c; double *d;} x; int i; { if (i) { printf("%d ", *x.c); } else { printf("%g\n", *x.d); } } void main() { bother(pc, 1); bother(pd, 0); } doesn't work either. pc and pd are pointers, so get passed on the scalar stack, while x is a union, so is looked for on the array stack. Once again, this doesn't seem to be forbidden by available descriptions of C, and is likely to happen on other "C machines". The question is whether the final semicolon in a 'struct' declaration is optional or not. I have been using two layouts for structures: typedef struct foo { type1 field1; /* rem1 */ ... typen fieldn; /* remn */ } foo; for important types; and for tiny little structs embedded in something: struct {type1 field1; ...; typen fieldn} dummy; both of which the VAX C compiler is perfectly happy with. But the Orion compiler, being written from the book, insists on the amazingly ugly ;} in both cases. Which compiler is right?