#include <stdio.h>
// 默认对齐
struct DefaultAligned {
char c;
int i;
};
// 按1字节对齐
#pragma pack(push, 1)
struct OneByteAligned {
char c;
int i;
};
#pragma pack(pop) // 恢复之前的对齐设置
int main() {
printf("Size of DefaultAligned: %zu bytes\n", sizeof(struct DefaultAligned));
printf("Size of OneByteAligned: %zu bytes\n", sizeof(struct OneByteAligned));
return 0;
}
Linux字节对齐小程序
最新推荐文章于 2024-07-03 20:56:21 发布