Re: Unions / unsigned char[]

Discussion in 'C Programming' started by John Temples, Sep 9, 2011.

  1. John Temples

    John Temples Guest

    On 2011-09-08, Kenneth Brody <> wrote:
    > Okay, I can't find C&V, but as I recall, accessing a union via anything
    > other than the one last written to is UB.


    It was ID (not UB) in C90, but that was removed in C99.

    --
    John W. Temples, III
     
    John Temples, Sep 9, 2011
    #1
    1. Advertising

  2. John Temples

    Stefan Ram Guest

    John Temples <> writes:
    >On 2011-09-08, Kenneth Brody <> wrote:
    >>Okay, I can't find C&V, but as I recall, accessing a union via anything
    >>other than the one last written to is UB.

    >It was ID (not UB) in C90, but that was removed in C99.


    Annex J, J.1 »unspecified behavior«, p1, of ISO/IEC
    9899:1999 (E) still contains:

    »The following are unspecified: (...)

    -- The value of a union member other than the last one
    stored into (6.2.6.1).«
     
    Stefan Ram, Sep 10, 2011
    #2
    1. Advertising

  3. John Temples

    Jens Gustedt Guest

    Am 09/10/2011 05:53 AM, schrieb Stefan Ram:
    > John Temples <> writes:
    >> On 2011-09-08, Kenneth Brody <> wrote:
    >>> Okay, I can't find C&V, but as I recall, accessing a union via anything
    >>> other than the one last written to is UB.

    >> It was ID (not UB) in C90, but that was removed in C99.

    >
    > Annex J, J.1 »unspecified behavior«, p1, of ISO/IEC
    > 9899:1999 (E) still contains:
    >
    > »The following are unspecified: (...)
    >
    > -- The value of a union member other than the last one
    > stored into (6.2.6.1).«


    This annex is not normative and just refers to the reasons why this
    might be UB with the paragraph number.

    I think the common understanding is that reading a member to which it
    was not written is UB *if* the value is a trap representation for that
    member. Since unsigned char may not have a trap representation it is
    save to access that member.

    Jens
     
    Jens Gustedt, Sep 11, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steffen Fiksdal

    void*, char*, unsigned char*, signed char*

    Steffen Fiksdal, May 8, 2005, in forum: C Programming
    Replies:
    1
    Views:
    605
    Jack Klein
    May 9, 2005
  2. Ioannis Vranos
    Replies:
    11
    Views:
    773
    Ioannis Vranos
    Mar 28, 2008
  3. Ioannis Vranos

    Padding bits and char, unsigned char, signed char

    Ioannis Vranos, Mar 28, 2008, in forum: C Programming
    Replies:
    6
    Views:
    623
    Ben Bacarisse
    Mar 29, 2008
  4. Alex Vinokur
    Replies:
    9
    Views:
    812
    James Kanze
    Oct 13, 2008
  5. pozz
    Replies:
    12
    Views:
    759
    Tim Rentsch
    Mar 20, 2011
Loading...

Share This Page