Alignment of bitfields inside unions
问题 I'm a bit puzzled by how the following code gets layed out in memory: struct Thing { union { unsigned value:24; uint8_t bytes[3]; }; Thing(int v) :value(v) {} void foo() { printf("Thing %p value=%d !\n", this, value); } } __attribute__((__packed__)); On gcc 3.3, 4.3 or 4.6 on Linux (without any special options I can think of - only "-Wall -g" on 4.6), the size of the structure is always 4: $ pahole ./union struct Thing { union { unsigned int value; /* 4 */ unsigned char bytes[3]; /* 3 */ }; [