Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site watdaisy.UUCP
Path: utzoo!watmath!watdaisy!ndiamond
From: ndiamond@watdaisy.UUCP (Norman Diamond)
Newsgroups: net.lang.c
Subject: Re: Re: struct element orderin vs. align
Message-ID: <6858@watdaisy.UUCP>
Date: Tue, 15-Jan-85 13:43:58 EST
Article-I.D.: watdaisy.6858
Posted: Tue Jan 15 13:43:58 1985
Date-Received: Wed, 16-Jan-85 04:00:05 EST
References: <133@ISM780B.UUCP>
Organization: U of Waterloo, Ontario
Lines: 33

> >Sigh,
> >        until you give me a subclass mechanism that ensures that the
> >representation of two data types share a common prefix, I'll rely on this
> >compiler hack.
> 
> You already have it:
> 
> struct {
> 	common part;
> 	union {
> 		distinct part1;
> 		distinct part2;
> 		...
> 	};
> };
> The distinct parts can of course be structures.
> This is the only guaranteed portable way to do this.

Nope; you're only guaranteed a common portion, which might or might not be
a prefix.  If some one really needs certain fields mapped to the beginning
of a structure, they have to take advantage of knowing how the compiler will
map the data.  If a person can depend on "part" being at the beginning of
that struct, then they can also depend on the ordering in every structure.

This is a very hard problem -- assuming that one wants a correct solution.

-- Norman Diamond

UUCP:  {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy@waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa

"Opinions are those of the keyboard, and do not reflect on me or higher-ups."