Struct pointer compatibility

后端 未结 6 2217
攒了一身酷
攒了一身酷 2020-12-11 03:13

Suppose we have two structs:

typedef struct Struct1
{
    short a_short;
    int id;
} Struct1;

typedef struct Struct2
{
    short a_short;
    int id;
             


        
6条回答
  •  感情败类
    2020-12-11 03:23

    struct pointers types always have the same representation in C.

    (C99, 6.2.5p27) "All pointers to structure types shall have the same representation and alignment requirements as each other."

    And members in structure types are always in order in C.

    (C99, 6.7.2.1p5) "a structure is a type consisting of a sequence of members, whose storage is allocated in an ordered sequence"

提交回复
热议问题