#pragma pack(1) struct my_align_struct { uint32 u0:8; uint32 u1:8; uint32 u2:8; uint32 u3:16; }; #pragma pack() sizeof(my_align_struct) == 5 // 默认情况下gcc是按照四字节对齐的,sizeof(my_align_struct) == 8.
struct my_align_struct { uint32 u0:8; uint32 u1:8; uint32 u2:8; uint32 u3:16; }__attribute__((packed, aligned(1)));