我正在linux上使用c中的結構。 我開始使用位字段和「壓縮」屬性,我碰到一個奇怪的行爲傳來:c結構中的壓縮位字段 - GCC
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
}
怎麼來的這兩個結構 - 這是完全一樣的 - 採取的字節數不同勢?
因爲't2 :: b'保證是一個不同的內存位置?想想數據競賽。 – 2014-09-13 11:26:00