Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Unions / unsigned char[]

Reply
Thread Tools

Re: Unions / unsigned char[]

 
 
John Temples
Guest
Posts: n/a
 
      09-09-2011
On 2011-09-08, Kenneth Brody <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      09-10-2011
John Temples <(E-Mail Removed)> writes:
>On 2011-09-08, Kenneth Brody <(E-Mail Removed)> 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).«

 
Reply With Quote
 
 
 
 
Jens Gustedt
Guest
Posts: n/a
 
      09-11-2011
Am 09/10/2011 05:53 AM, schrieb Stefan Ram:
> John Temples <(E-Mail Removed)> writes:
>> On 2011-09-08, Kenneth Brody <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
unsigned long to unsigned char ashtonn@gmail.com Python 1 06-01-2005 07:00 PM
comparing unsigned long and unsigned int sridhar C Programming 6 11-03-2004 03:52 AM
unsigned int const does not match const unsigned int Timo Freiberger C++ 3 10-30-2004 07:02 PM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments