Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: bit value of a negative number Date: Sat, 30 Jul 2016 13:59:10 -0700 Organization: None to speak of Lines: 33 Message-ID: References: <159d5df7-d640-40b1-9866-2bb16d7769ee@googlegroups.com> <87a8gzxv8b.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="27970"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IDSNb1LuLkgL+SBXlEqv6" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:tqjBDFjSjkL6/M6YxUhUzu9UNj8= sha1:/Yer3KT50RK5+7raD+Qj0xNsgDg= Xref: csiph.com comp.lang.c:91378 James Kuyper writes: > On 07/30/2016 07:31 AM, Stefan Ram wrote: [...] > As I remember, the fact that it was technically problematic was due to > an explicit statement to that effect in the C90 standard: reading the > value of a member of a union that was not the same as the one last > written to was problematic in some way - but I don't have a copy of C90 > that I can reference to confirm that. The relevant clause should be in > the semantics section of the description of the member selection operator. C90 6.3.2.3 says: With one exception, if a member of a union object is accessed after a value has been stored in a different member of the object, the behavior is implementation-defined. (The exception is the common initial sequence rule.) A footnote on that sentence says: The "byte orders" for scalar types are invisible to isolated programs that do not indulge in type punning (for example, by assigning to one member of a union and inspecting the storage by accessing another member that is an appropriately sized array of character type), but must be accounted for when conforming to externally imposed storage layouts. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"