C 确实有嵌套的结构/联合/枚举,但没有嵌套的 typedef。
struct A { typedef struct B { int x; } B; }; //WRONG
struct A { struct { int x; } b; }; //OK - an anonymous nested struct w/ an instance
struct A { struct { int x; }; }; //OK - an anonymous nested struct w/out an instance; x effectively belongs to `struct A`
struct A { struct B { int x; } b; }; //OK, the `struct B` type also becomes available in the outer scope
struct A { struct B { int x; }; }; //WRONG, an tagged nested struct needs at least 1 instance
嵌套的结构/联合/枚举可以是匿名的(未标记),在这种情况下它们成为外部结构/联合的一部分或被标记。
匿名内部结构/联合也可以在不定义实例的情况下逃脱,在这种情况下,内部成员递归地成为外部结构/联合的成员。
标记的嵌套结构/联合/枚举需要实例,它就像带有实例的匿名嵌套结构/联合/枚举,除了标记类型也可供以后使用,表现得好像它是一个独立的外部范围结构/联合/枚举定义.
将标记的 struct/union/enum 简单地放在外部范围中而不是将其混淆地嵌套在另一个 struct/union 中可能是明智的。