Tag: packed

c结构中的压缩位字段 – GCC

我在linux上使用c中的结构。 我开始使用位字段和“打包”属性,我遇到了一个奇怪的行为: struct t1 { int a:12; int b:32; int c:4; }__attribute__((packed)); struct t2 { int a:12; int b; int c:4; }__attribute__((packed)); void main() { printf(“%d\n”,sizeof(t1)); //output – 6 printf(“%d\n”,sizeof(t2)); //output – 7 } 为什么两个结构 – 完全相同 – 采用不同的字节数?