Reputation: 37297
schot's answer is a good one. He claimed that
- Tags (names of structures, unions and enumerations).
I think that the tags for structures, unions and enumerations have different namespaces, so that this code is completely fine:
// In the same scope
struct T {};
union T {};
enum T {};
But inferring from the quotation above, it looks like all tags share the same namespace. Is the answer not clear enough or am I wrong?
Upvotes: 4
Views: 537
Reputation: 106092
No, they do not have separate namespaces. There is only one namespace for tags. This means
struct TS{};
union TU{};
int TS, TU;
is valid while
struct T{};
union T{};
is not. Two declarations of T
are in the same namespace.
Upvotes: 2
Reputation: 4920
The answer to your question:
Tag names: all identifiers declared as names of structs
, unions
and enumerated types. Note that all three kinds of tags share one name space.
Just quoting this from reference guide.
At the point of lookup, the name space of an identifier is determined by the manner in which it is used:
- identifier that follows the keyword
struct
,union
, orenum
is looked up in the tag name space.
Upvotes: 1
Reputation: 121407
No.
All the tags share the same namespace. So you are not allowed to have:
struct T {...};
union T {...};
enum T {...};
C11 draft N1570, 6.2.3 Name spaces of identifiers explicitly add s footnote.
32) There is only one name space for tags even though three are possible.
Upvotes: 7