取消结构体的自动对齐

使用  __attribute__((packed))

例如

struct TEST {

  short x;

  int y;

}__attribute__((packed));

此时sizeof(TEST)等于6,可见此时不是自动对齐

 

或者使用#pragma pack,详见百度百科

 

posted @ 2015-04-11 19:20  Netop  阅读(1307)  评论(0编辑  收藏  举报