Structure Padding in C

后端 未结 2 1612
长发绾君心
长发绾君心 2021-01-23 17:15

If I have a structure definition in C of the following

typedef struct example 
{
  char c;
  int ii;
  int iii;
};

What should be the memory al

2条回答
  •  广开言路
    2021-01-23 18:00

    Under normal 32 bit it should take 12 bytes - the c field will be padded. This is architecture and compiler depended, however.

    You can always use a pragma for the compiler to declare the alignment for the structure (and for some compilers, change the default alignment).

提交回复
热议问题