[英]How does the c compiler execute when we include a pointer declaration to a structure which we haven't finished defining yet?
struct noderecord {
struct noderecord* next;
int data;
};
how is the pointer next declared without some error?如何在没有错误的情况下声明下一个指针? we have added one more element subsequently after declaring a pointer, wouldn't the pointer element be of the wrong size?
我们在声明一个指针之后又添加了一个元素,指针元素的大小不会错误吗?
All pointers to structures in a C implementation are the same size as each other, per C 2018 6.2.6.1 28:根据 C 2018 6.2.6.1 28,C 实现中的所有指向结构的指针彼此大小相同:
… All pointers to structure types shall have the same representation and alignment requirements as each other…
...所有指向结构类型的指针都应具有相同的表示形式和 alignment 要求彼此...
So, to know how big a pointer to a structure is, the compiler does not need to know anything about the structure, just that the pointer is pointing to some type of structure.因此,要知道指向结构的指针有多大,编译器不需要知道任何关于结构的信息,只需知道指针指向某种类型的结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.