Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do struct tags, union tags and enum tags have separate namespaces?

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?

like image 825
iBug Avatar asked Oct 27 '25 05:10

iBug


2 Answers

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.

like image 147
P.P Avatar answered Oct 28 '25 21:10

P.P


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.

like image 37
haccks Avatar answered Oct 28 '25 19:10

haccks