access union member via ptr

S

S.Tobias

In DR#236 (recently brought about in "contiguity of arrays" thread)
http://www.open-std.org/JTC1/SC22/WG14/www/docs/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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top