struct element orderin vs. align

Norman Diamond ndiamond at watdaisy.UUCP
Wed Jan 16 04:43:58 AEST 1985


> >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 at waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet at csnet-relay.arpa

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



More information about the Comp.lang.c mailing list