Structure padding and packing

前端 未结 9 1403
太阳男子
太阳男子 2020-11-21 05:04

Consider:

struct mystruct_A
{
   char a;
   int b;
   char c;
} x;

struct mystruct_B
{
   int b;
   char a;
} y;

The sizes of the structur

9条回答
  •  孤城傲影
    2020-11-21 05:24

    There are no buts about it! Who want to grasp the subject must do the following ones,

    • Peruse The Lost Art of Structure Packing written by Eric S. Raymond
    • Glance at Eric's code example
    • Last but not least, don't forget the following rule about padding that a struct is aligned to the largest type’s alignment requirements.

提交回复
热议问题