既然你问这个语言“为什么”的确切原因,我假设你需要一些精确的参考.如果你发现那个学究,只需跳过笔记……
它的作用是因为两件事:
>所有指向结构类型的指针都具有相同的表示形式(请注意,就标准C而言,并非所有指针类型都是如此).[1]因此,编译器有足够的信息来为指针到结构类型的所有用法生成适当的代码.
>标签命名空间(struct,enum,union)确实与所有翻译单元兼容.[2]因此,两个结构(即使一个未完全定义,即它缺少成员声明)是同一个.
(顺便说一句,#import是非标准的.)
[1]根据n1256§6.2.5.27:
All pointers to structure types shall have the same representation and alignment requirements as each other. Pointers to other types need not have the same representation or alignment requirements.
[2]根据n1256§6.2.7.1:
two structure, union, or enumerated types declared in separate translation units are compatible if their tags and members satisfy the following requirements: If one is declared with a tag, the other shall be declared with the same tag. If both are complete types, then the following additional requirements apply: [does not concern us].