J
James Brown
All,
Could anyone explain why the following is an error:
void foo( struct FOO { int x; } f1 )
{
}
int main()
{
struct F f2;
return 0;
}
I get a 'f2' uses undefined struct 'FOO' error. So it looks like the scope
of type definitions declarated in a function prototype are essentially
'private' (i.e. contained) within the function and cannot be used outside.
Is this correct?
This is in contrast to nested structures defined within other structures:
i.e.
struct FOO
{
struct BAR
{
int y;
} b1;
};
struct BAR b2; /* this is ok */
In this last example, I can declare 'struct BAR b2' because I believe nested
structures use the name symbol namespace as 'global' tags. Really what is
confusing me, is that there is an apparent difference in 'namespace rules'
between structures declared in function prototypes, and nested structures
declared in container structures.
I guess my question is this: Does each function-object manage it's own
symbol namespace which is distinct from the global symbols? Or does this
namespace behaviour extend to any kind of nested block?
i.e.
void foo(struct FOO { int x; } f1)
{
{
struct FOO
{
int x;
} f1; /* seems legal, at least on the C-compiler I'm using */
}
}
Perhaps somebody could clarify what the namespace rules are for symbols, and
comment on if there are any differences between C89/90/99?
thanks,
James
Could anyone explain why the following is an error:
void foo( struct FOO { int x; } f1 )
{
}
int main()
{
struct F f2;
return 0;
}
I get a 'f2' uses undefined struct 'FOO' error. So it looks like the scope
of type definitions declarated in a function prototype are essentially
'private' (i.e. contained) within the function and cannot be used outside.
Is this correct?
This is in contrast to nested structures defined within other structures:
i.e.
struct FOO
{
struct BAR
{
int y;
} b1;
};
struct BAR b2; /* this is ok */
In this last example, I can declare 'struct BAR b2' because I believe nested
structures use the name symbol namespace as 'global' tags. Really what is
confusing me, is that there is an apparent difference in 'namespace rules'
between structures declared in function prototypes, and nested structures
declared in container structures.
I guess my question is this: Does each function-object manage it's own
symbol namespace which is distinct from the global symbols? Or does this
namespace behaviour extend to any kind of nested block?
i.e.
void foo(struct FOO { int x; } f1)
{
{
struct FOO
{
int x;
} f1; /* seems legal, at least on the C-compiler I'm using */
}
}
Perhaps somebody could clarify what the namespace rules are for symbols, and
comment on if there are any differences between C89/90/99?
thanks,
James