union ( members with same name )

  • Thread starter Frederico Faria
  • Start date
F

Frederico Faria

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
 
J

Jack Klein

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
 
M

Martin Ambuhl

(e-mail address removed) (Frederico Faria) wrote (04 Jul 2003) in
/ 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.
 
M

Mike Wahler

Frederico Faria said:
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
 
F

Frederico Faria

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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top