简体   繁体   中英

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:

… All pointers to structure types shall have the same representation and alignment requirements as each other…

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM