结构体 字节对齐的练习 2018.1.7 2024.12.9 C-lang 219 1 分钟 分析结构体大小 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 struct S1 { char c1; double d; char c2; char c3; }; struct S2 { char c1; char c2; char c3; double d; }; struct S3 { char c1; S1 s; char c2; char c3; }; 分析结构体大小 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #pragma pack(1) struct S1 { char c1; double d; char c2; char c3; }; #pragma pack() struct S3 { char c1; S1 s; char c2; char c3; }; 分析结构体大小 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #pragma pack(4) struct S1 { char c1; double d; char c2; char c3; }; #pragma pack() struct S3 { char c1; S1 s; char c2; char c3; }; 分析结构体大小 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 struct S1 { char c1; double d; char c2; char c3; }; #pragma pack(1) struct S3 { char c1; S1 s; char c2; char c3; }; #pragma pack() 作者:luodaoyi 链接:https://luodaoyi.com/posts/结构体-字节对齐的练习-结构体字节对齐的练习/ 许可:CC BY-NC-SA 4.0