Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watmath.UUCP Path: utzoo!watmath!kpmartin From: kpmartin@watmath.UUCP (Kevin Martin) Newsgroups: net.lang.c Subject: Shared initial struct elements... history provides an answer? Message-ID: <10885@watmath.UUCP> Date: Sun, 13-Jan-85 22:53:49 EST Article-I.D.: watmath.10885 Posted: Sun Jan 13 22:53:49 1985 Date-Received: Mon, 14-Jan-85 04:25:09 EST References: <7112@brl-tgr.ARPA> <289@link.UUCP> <974@hou3c.UUCP> Reply-To: kpmartin@watmath.UUCP (Kevin Martin) Organization: U of Waterloo, Ontario Lines: 64 Summary: The problem: struct shared { int discriminant; type1 shared1; type2 shared2; }; struct version1 { struct shared _x_; type3 unshared1; type4 unshared2; }; /* etc. */ The problem is this funny _x_ that must be introduced in the names of the shared parts. The history: Early C compilers were somewhat lax about structures, and you could say something like struct version1 { struct { int discriminant; type1 shared1; type2 shared2; }; /* note: no _x_ */ type3 unshared1; type3 unshared2; }; And everything worked. This disappeared about the same time typed struture pointers appeared. The solution: In a structure or union declaration, if an element declaration of type struct or union is given *with no declarators*, the elements of the inner struct or union are re-declared (additionally declared?) as elements of the outer struct or union, with their offsets being the offset of the start of the inner struct/union plus their offset within that struct or union. (phew!). Note that the inner elements would have to be unique in the outer struct/ union. The solved example: struct shared { int discriminant; type1 shared1; type2 shared2; }; struct version1 { struct shared; type3 unshared1; type4 unshared2; }; /* etc. */ This change doesn't break existing code, and reduces the need for the programmer to create extra names for those funny nested structs. No, Henry, we haven't implemented it. We're waiting for the standard before we make any more compiler changes. But I wanted to mention this hare-brained scheme before someone decides to use another hare-brained scheme... Kevin Martin, UofW Software Development Group