access union member via ptr

Discussion in 'C Programming' started by S.Tobias, Oct 28, 2004.

  1. S.Tobias

    S.Tobias Guest

    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.)


    --
    Stan Tobias
    sed 's/[A-Z]//g' to email
    S.Tobias, Oct 28, 2004
    #1
    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. Sid
    Replies:
    5
    Views:
    1,072
  2. Heiko Vogel
    Replies:
    3
    Views:
    557
    Method Man
    Sep 14, 2004
  3. franco ziade

    const ptr to const ptr ?

    franco ziade, Feb 17, 2005, in forum: C Programming
    Replies:
    3
    Views:
    394
    franco ziade
    Feb 17, 2005
  4. G Fernandes
    Replies:
    9
    Views:
    591
    DHOLLINGSWORTH2
    Feb 27, 2005
  5. Jason

    difference between *ptr++ and ++*ptr ?

    Jason, May 15, 2005, in forum: C Programming
    Replies:
    19
    Views:
    6,535
    Chris Torek
    May 19, 2005
Loading...

Share This Page