Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!husc6!spdcc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Union type conversions Message-ID: <5205@haddock.ISC.COM> Date: 15 Jul 88 16:24:44 GMT References: <5754@bloom-beacon.MIT.EDU> <1180@mcgill-vision.UUCP> <3714@ece-csc.UUCP> <12490@mimsy.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 19 In article <12490@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >In article <3714@ece-csc.UUCP> jnh@ece-csc.UUCP (Joseph Nathan Hall) writes: >[quoting from the *de*scriptive part of the text [K&R], which says only that] >> "In effect, a union is a structure in which all members have >> OFFSET ZERO [emphasis added] ..." > >The point of this quote is to warn users that writing on any one >element of a union *may* stomp any other element, not that it *must* >stomp other elements. Alan Bowler is right; unions make few >guarantees. On the other hand, a compiler that does not conserve >storage with union definitions is probably not worth using. Except possibly as a debugging tool to catch accidental punning. Anyway, the dpANS does guarantee that "a pointer to a union object, suitably cast, points to each of its members ... and vice versa" (3.5.2.1). So an implementation that tries to make structs out of unions would have to do some gymnastics if it's to remain ANSI-conformant. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint