【发布时间】:2021-12-20 05:33:52
【问题描述】:
为什么结构成员必须始终有一个标识符?答案当然是因为语言是这样定义的,但我想了解其背后的原因。
typedef union {
int a;
struct {
int a; //Why is an identifier necessary here?
int b;
} s;
} u;
【问题讨论】:
-
如果没有标识符,您将如何访问该字段?
-
你可以有“未命名的成员”——见port70.net/~nsz/c/c11/n1570.html#6.7.2.1p13
-
@pmg 这仅适用于
struct和union成员。