Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > access union member via ptr

Reply
Thread Tools

access union member via ptr

 
 
S.Tobias
Guest
Posts: n/a
 
      10-28-2004
In DR#236 (recently brought about in "contiguity of arrays" thread)
http://www.open-std.org/JTC1/SC22/WG...ocs/dr_236.htm
at the end ("Committee Discussion") it has been said that Example 2
is invalid, because it violates 6.5#7.

I kindly ask you to explain exactly why.

My (counter) arguments:

6.5#7 talks about accessing a *value*, whereas in Example 2 a
new value is stored, without accessing the previous one. (In the
corrected example in the DR it's been explicitly said: "union type
must be used when changing effective type" - I don't see how 6.5
backs it up.)

At the end of 6.5.2.3 ("Structure and union members") in Example 3
(I have asked in clc about this example a few weeks ago, but what
I asked had nothing to do with the current issue; I'll renew that
question soon anyway) in the "wrong" part, in function f(), union
members (which happen to have struct type, but this is irrelevant)
are accessed through pointers (explicitly passed from g()).
(It's even worse: only a part of *p2 is changed (it's easy to
imagine struct t2 had more members), whereas in DR Ex2 the whole
union member modification is attempted.)

(And I know that the "wrong" part of the example illustrates bad
use of "->m" without the union context; I'm asking about "p->"
side and I consider this part of the example to be correct.)


--
Stan Tobias
sed 's/[A-Z]//g' to email
 
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
difference between *ptr++ and ++*ptr ? Jason C Programming 19 05-19-2005 04:50 PM
is (!ptr) or (ptr) valid way to check for NULL or NOT NULL? G Fernandes C Programming 9 02-27-2005 03:07 AM
const ptr to const ptr ? franco ziade C Programming 3 02-17-2005 04:30 AM
How to convert a double **ptr in a double const ** const ptr? Heiko Vogel C Programming 3 09-14-2004 10:23 AM
what's the difference between delete ptr and ptr=0 -dont they accomplish the same Sid C++ 5 07-29-2004 03:42 AM



Advertisments