关于对齐方式

xiaoxiao2021-02-27  264

DEC   : #pragma pack(1)  SUN   : #pragma pack(1)  AIX   : 编译时 -q align=packed  HP-UX : #pragma pack 1 

1) 结构内部成员的pack  struct foo  {      char a;      int  b __attribute__ ((packed));  };  2) 整个结构的pack  struct foo  {      char a;      int  b;  }__attribute__ ((packed));  3) 文件范围的pack  #pragma pack(1)  struct foo  {      char a;      int  b;  };  ... ...  4) 编译选项的pack  -fpack-struct  但这是最危险的做法,因为这样做可能会使库函数和你的程序对结构内成员的偏移理  解不一致。

转载请注明原文地址: https://www.6miu.com/read-10856.html

最新回复(0)