结构标签、联合标签和枚举标签是否有单独的命名空间?

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

schot's answer 不错。他声称

  • Tags (names of structures, unions and enumerations).

我认为结构、联合和枚举的标签有不同的命名空间,所以这段代码完全没问题:

// In the same scope
struct T {};
union T {};
enum T {};

但从上面的引文推断,似乎所有标签都共享同一个命名空间。是回答不够清楚还是我错了?

不,它们没有单独的名称空间。标签只有一个命名空间。这意味着

struct TS{};
union TU{};
int TS, TU;

时有效
struct T{};
union T{}; 

不是。 T 的两个声明在同一个命名空间中。

没有

所有标签共享同一个命名空间。所以你不能拥有:

struct T {...};
union T {...};
enum T {...};

C11 draft N1570, 6.2.3 Name spaces of identifiers 明确添加脚注。

32) There is only one name space for tags even though three are possible.

您问题的答案:

标签名称:声明为structsunions和枚举类型名称的所有标识符。请注意,所有三种标签共享一个名称 space.

只是引用 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, or enum is looked up in the tag name space.