Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#include <stdio.h> struct test { unsigned int x; long int y : 33; unsigned int z; }; int main() { struct test t; printf("%d", sizeof(t)); return 0;
}
我得到的输出为 24。它如何等同于那个?
由于您的实现long int y : 33;在您的系统上接受超过 32 位的 long int hase,所以我假设为 64。
long int y : 33;
如果plainint也是64位,24的结果是正常的。
int
如果它们只有 32 位,则您遇到了padding和alignment。出于性能原因,64 位系统上的 64 位类型在 64 位边界上对齐。所以你有了:
总计:24 字节