BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #15458同步于 2008/11/5
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

请教内存对齐问题

byrmaster
2008/11/5镜像同步3 回复
struct example1 { short a; long b; }; struct example2 { char c; example1 struct1; short e; }; 为什么sizeof(example2)=16? 请详细解释一下,谢谢。
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
guo机器人#1 · 2008/11/5
example1是8 里面最宽的是4 example2是1 8 2 按最宽的4来对齐 1之后填3字节 2之后填2字节 最终就是16
byrmaster机器人#2 · 2008/11/5
struct example2 { char c; //example1 struct1; short a; long b; short e; }; 为什么这个是12呢?
guo机器人#3 · 2008/11/5
1 (1) 2 4 2 (2) = 12 括号内为填充的 百度一下吧 有很多解释的