【发布时间】:2012-12-18 06:18:15
【问题描述】:
我在 C 语言中有以下嵌套结构。(64 位)
typedef struct {
int a;
int b;
int c;
struct {
int ab;
long bc;
}
int d;
} Test;
I see that,
a = 4 bytes
b = 4 bytes
c = 4 bytes
padding1 = 4 bytes
inner structure = 16 bytes ( 4 bytes for ab, 4 bytes padding, 8 bytes for bc)
d = 4 bytes
padding2 = 4 bytes
sizeof(Test) 返回 40 个字节。
我的问题:
padding1 -> 为什么这是 4 个字节?这是因为内部结构本身应该对齐吗? (另外,它是否与 8 字节(长)或 16 字节(内部大小)边界对齐。?)
padding2 -> 这是 4 字节填充,因为在结构内部完成了最大对齐(即 8)??
谢谢,
【问题讨论】:
-
您的代码无法编译。请仅发布经过验证以产生声明结果的真实编译代码。
标签: c 64-bit nested padding structure