Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #91378

Re: bit value of a negative number

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: bit value of a negative number
Date 2016-07-30 13:59 -0700
Organization None to speak of
Message-ID <lntwf66dwh.fsf@kst-u.example.com> (permalink)
References <159d5df7-d640-40b1-9866-2bb16d7769ee@googlegroups.com> <87a8gzxv8b.fsf@bsb.me.uk> <punning-20160730120244@ram.dialup.fu-berlin.de> <nniald$65o$1@dont-email.me>

Show all headers | View raw


James Kuyper <jameskuyper@verizon.net> 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  <http://www.ghoti.net/~kst>
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"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

bit value of a negative number sinbad <sinbad.sinbad@gmail.com> - 2016-07-30 02:38 -0700
  Re: bit value of a negative number Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-07-30 02:50 -0700
  Re: bit value of a negative number Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-07-30 11:42 +0100
    Re: bit value of a negative number James Kuyper <jameskuyper@verizon.net> - 2016-07-30 09:38 -0400
      Re: bit value of a negative number "James R. Kuyper" <jameskuyper@verizon.net> - 2016-07-30 11:39 -0400
      Re: bit value of a negative number Keith Thompson <kst-u@mib.org> - 2016-07-30 13:59 -0700
    Re: bit value of a negative number Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-07-30 15:16 +0100
      Re: bit value of a negative number Tim Rentsch <txr@alumni.caltech.edu> - 2016-07-31 06:31 -0700
        Re: bit value of a negative number Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-07-31 17:28 +0100
      Re: bit value of a negative number supercat@casperkitty.com - 2016-07-31 13:19 -0700
        Re: bit value of a negative number Ike Naar <ike@iceland.freeshell.org> - 2016-07-31 20:46 +0000
    Re: bit value of a negative number Tim Rentsch <txr@alumni.caltech.edu> - 2016-07-30 14:21 -0700
      Re: bit value of a negative number supercat@casperkitty.com - 2016-07-31 13:37 -0700
        Re: bit value of a negative number Tim Rentsch <txr@alumni.caltech.edu> - 2016-07-31 16:59 -0700
    Re: bit value of a negative number supercat@casperkitty.com - 2016-07-31 12:56 -0700
  Re: bit value of a negative number Barry Schwarz <schwarzb@dqel.com> - 2016-07-30 10:15 -0700
  Re: bit value of a negative number Tim Rentsch <txr@alumni.caltech.edu> - 2016-07-30 10:25 -0700

csiph-web