union ( members with same name )

Discussion in 'C Programming' started by Frederico Faria, Jul 4, 2003.

  1. Is possible I have a union with its members having the same name as below ?

    union {
    MyType myVar;
    MyType myVar;
    MyType myVar;
    OtherType otherVar;

    } MyUnion;


    I am using "gcc" but it don't compile. do I need any compile option ?

    Thank you,

    Frederico Faria
     
    Frederico Faria, Jul 4, 2003
    #1
    1. Advertising

  2. Frederico Faria

    Jack Klein Guest

    On 4 Jul 2003 15:38:57 -0700, (Frederico
    Faria) wrote in comp.lang.c:

    > Is possible I have a union with its members having the same name as below ?


    No. Each one must have a different name.

    >
    > union {
    > MyType myVar;
    > MyType myVar;
    > MyType myVar;
    > OtherType otherVar;
    >
    > } MyUnion;
    >
    >
    > I am using "gcc" but it don't compile. do I need any compile option ?
    >
    > Thank you,
    >
    > Frederico Faria


    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
     
    Jack Klein, Jul 5, 2003
    #2
    1. Advertising

  3. (Frederico Faria) wrote (04 Jul 2003) in
    news: / comp.lang.c:

    > Is possible I have a union with its members having the same name
    > as below ?
    >
    > union {
    > MyType myVar;
    > MyType myVar;
    > MyType myVar;
    > OtherType otherVar;
    >
    > } MyUnion;
    >
    >
    > I am using "gcc" but it don't compile. do I need any compile
    > option ?


    What do you think such a "union" could mean? If you referred to
    MyUnion.myVar, which one do you think it would be? Of course this is
    illegal. Even gcc doesn't have a compile option that could make
    sense of this hash.



    --
    Martin Ambuhl
    Returning soon to the
    Fourth Largest City in America
     
    Martin Ambuhl, Jul 5, 2003
    #3
  4. Frederico Faria

    Mike Wahler Guest

    Frederico Faria <> wrote in message
    news:...
    > Is possible I have a union with its members having the same name as below

    ?

    No it is not. If it were, how could you distinguish one
    from another?

    >
    > union {
    > MyType myVar;
    > MyType myVar;
    > MyType myVar;
    > OtherType otherVar;
    >
    > } MyUnion;
    >
    >
    > I am using "gcc" but it don't compile.


    Of course not.

    >do I need any compile option ?


    You need to use the language correctly.

    What possible purpose could fulfilling your
    above stated desire have?

    -Mike
     
    Mike Wahler, Jul 5, 2003
    #4
  5. I received a RPC-XDR model to interface with other software.
    The XDR model have o type below:

    union X721EventInfo
    switch (X721EventType eventType) {
    case AT_COMMUNICATIONS : X721AlarmInfo alarmInfo;
    case AT_QUALITY_OF_SERVICE : X721AlarmInfo alarmInfo;
    case AT_PROCESSING_ERROR : X721AlarmInfo alarmInfo;
    case AT_EQUIPMENT : X721AlarmInfo alarmInfo;
    case ST_INFORMATION : X732ManagementState managementState;
    };


    I was confuse because it never compile with gcc. Then now, I changed
    the X721EventInfo definition to have the members with diferent names.

    Thank you,

    Faria



    "Mike Wahler" <> wrote in message news:<be53q4$bhh$>...
    > Frederico Faria <> wrote in message
    > news:...
    > > Is possible I have a union with its members having the same name as below

    > ?
    >
    > No it is not. If it were, how could you distinguish one
    > from another?
    >
    > >
    > > union {
    > > MyType myVar;
    > > MyType myVar;
    > > MyType myVar;
    > > OtherType otherVar;
    > >
    > > } MyUnion;
    > >
    > >
    > > I am using "gcc" but it don't compile.

    >
    > Of course not.
    >
    > >do I need any compile option ?

    >
    > You need to use the language correctly.
    >
    > What possible purpose could fulfilling your
    > above stated desire have?
    >
    > -Mike
     
    Frederico Faria, Jul 8, 2003
    #5
    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. Matt Garman
    Replies:
    1
    Views:
    670
    Matt Garman
    Apr 25, 2004
  2. Denis Remezov

    Address of union members

    Denis Remezov, Jun 30, 2004, in forum: C++
    Replies:
    6
    Views:
    385
    Mike Wahler
    Jul 1, 2004
  3. Barry Schwarz

    Accessing alternate union members

    Barry Schwarz, Jan 17, 2004, in forum: C Programming
    Replies:
    2
    Views:
    356
    Barry Schwarz
    Jan 18, 2004
  4. Peter Dunker

    union in struct without union name

    Peter Dunker, Apr 26, 2004, in forum: C Programming
    Replies:
    2
    Views:
    876
    Chris Torek
    Apr 26, 2004
  5. Johannes Schaub (litb)

    Reading from different union members

    Johannes Schaub (litb), Dec 30, 2009, in forum: C Programming
    Replies:
    5
    Views:
    499
    Tim Rentsch
    Jan 13, 2010
Loading...

Share This Page