Are structs of variables of the same type layout compatible with a struct containing an array of that type?

后端 未结 2 712
孤独总比滥情好
孤独总比滥情好 2020-12-11 00:41

Are these 2 structs layout-compatible?

struct One {
    float x, y, z;
};

struct Two {
    float c[3];
};

Both contains 3 floats, so in a

2条回答
  •  不思量自难忘°
    2020-12-11 01:23

    The compiler is allowed to add padding between members in a class or struct.

    Array elements are in contiguous locations.

    They may not be layout compatible depending on how the compiler organizes the members in the struct.

提交回复
热议问题