简体   繁体   English

当我们包含指向尚未完成定义的结构的指针声明时,c 编译器如何执行?

[英]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.

相关问题 如果我们还没有消费任何消息,如何确定 Kafka 主题分区偏移量 - How to determine Kafka topic partition offset if we haven't consumed any messages yet 为什么我们不能推广指针声明? - Why can't we generalize the pointer declaration? 为什么我们在C中为链表定义Structure时不会出错 - how come we don't get error when we define Structure in C for linked list 当我们将值存储在scanf中的变量中时,c编译器如何找到值的地址? - how does the c compiler find the address of a value when we are storing that in scanf in a variable? 当我们在C中使用两个指针时会发生什么? - What does happen when we equation two pointer in C? 当我们用C编写printf()时,是在声明它还是在定义它? - When we write printf() in C, are we declaring it or defining? 我们什么时候使用结构变量和结构指针? - When do we use structure variable and structure pointer? 我的获取功能有问题吗? 我们还没有在课堂上讨论fgets。 只得到 - Is there something wrong with my gets function? we haven't been though about fgets yet in class. only gets 我们不能包含.c文件吗? - Can't we include .c file? 当指针指向 memory 中的结构位置时,我们如何才能通过该地址访问结构字段? - When pointer points to structure location in memory how can we access structures fields just through that address?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM