如果我声明一个这样的结构:
struct
{
int a;
char b;
} ident;
该结构有类型吗? (即未指定的类型、默认类型等)。
相反,如果我声明一个结构,例如:
struct J
{
int a;
char b;
} ident;
我们可以说ident
是一个类型的结构变量struct J
.
After
struct { int a; char b; } ident;
ident
has an “anonymous structure type” and you won’t be able to declare another variable of the same type*). That is, two anonymous structure types are never compatible. If you did, for example,
struct { int a; char b; } ident2;
然后,ident
and ident2
将是不同的(尽管相同)类型和类似的分配
ident2 = ident;
将违反约束(编译器必须给出诊断消息并且可能拒绝编译,大多数编译器可能会这样做)。
*) Some compilers have extensions to allow it. For example, with Gcc, you can do:
typeof(ident) ident2 = ident;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)