探究struct对齐

来源:互联网 发布:数据有效性 文本长度 编辑:程序博客网 时间:2024/05/22 04:28

一直犯了一个想当然的错误
struct A {
int a;
char b;
};
一直认为a是四字节对齐,b是1字节对齐,所以A的size是5个字节。
struct A自身也需要对齐,是4字节对齐,所以A的size是8个字节。
参考:http://blog.chinaunix.net/uid-14802518-id-2784907.html

0 0