Why does a struct consisting of a char, short, and char (in that order), when compiled in C++ with 4-byte packing enabled, come to a 6-byte struct?

后端 未结 3 913
遥遥无期
遥遥无期 2021-01-14 01:37

I thought I understood how C/C++ handled struct member alignment. But I\'m getting strange results for a particular arrangement in Visual Studio 2008 and 2010.

Speci

3条回答
  •  灰色年华
    2021-01-14 02:08

    The Visual Studio's C compiler with this command option /Zp[n] where a struct is packed on a n-byte boundary, this is where the #pragma pack directive comes in, members of the structure are aligned on a boundary that is multiple of n.

提交回复
热议问题