T
tapeesh
I created a C file say struct.c with the following structure
declarations in the same file
struct A
{
union key
{
int i;
float f;
}k1;
};
struct B
{
union key
{
int i;
float f;
}k2;
};
When I compiled this code using
gcc -c struct.c
I got a error
"redefinition of `union key'" at the definition of "union key" in
struct B.
Is it not that the scope "union key" defined in struct A is limited to
struct A? From the behaviour it looks like that nested unions have
global scope.
Can anyone provide me the reason for such behavior?
When i made the file as struct.cpp it compiled without any problem.
Similar is the behaviour if I nest a struct inside a struct..
declarations in the same file
struct A
{
union key
{
int i;
float f;
}k1;
};
struct B
{
union key
{
int i;
float f;
}k2;
};
When I compiled this code using
gcc -c struct.c
I got a error
"redefinition of `union key'" at the definition of "union key" in
struct B.
Is it not that the scope "union key" defined in struct A is limited to
struct A? From the behaviour it looks like that nested unions have
global scope.
Can anyone provide me the reason for such behavior?
When i made the file as struct.cpp it compiled without any problem.
Similar is the behaviour if I nest a struct inside a struct..