M
main()
Hi all,
I wanted to have a union which has two structures in it.
So i did this,
union {
struct{
int a;
int b;
};
struct{
float c;
};
}un;
I did not want to name the two inner structures, because i wanted to
access the members like this,
<union name>.<member name>
instead of
<union name>.<structure name>.<member name>
My question is, Is this valid C?
I also observed that if i have a union like this ,
union {
struct{
int a;
int b;
};
struct{
float a;
float b;
};
}un;
Compiler doesn't give me any error.
If i say, 'un.a' how will it know whether i'm using float a or int
a ?
Thanks for your time,
Yugi.
I wanted to have a union which has two structures in it.
So i did this,
union {
struct{
int a;
int b;
};
struct{
float c;
};
}un;
I did not want to name the two inner structures, because i wanted to
access the members like this,
<union name>.<member name>
instead of
<union name>.<structure name>.<member name>
My question is, Is this valid C?
I also observed that if i have a union like this ,
union {
struct{
int a;
int b;
};
struct{
float a;
float b;
};
}un;
Compiler doesn't give me any error.
If i say, 'un.a' how will it know whether i'm using float a or int
a ?
Thanks for your time,
Yugi.