1 Star 2 Fork 1

wenqzheng/Building-Low-Latency-Applications-with-CPP

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
alignment.cpp 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
#include <cstdio>
#include <cstdint>
#include <cstddef>
struct PoorlyAlignedData {
char c;
uint16_t u;
double d;
int16_t i;
};
struct WellAlignedData {
double d;
uint16_t u;
int16_t i;
char c;
};
#pragma pack(push, 1)
struct PackedData {
double d;
uint16_t u;
int16_t i;
char c;
};
#pragma pack(pop)
int main() {
printf("PoorlyAlignedData c:%lu u:%lu d:%lu i:%lu size:%lu\n",
offsetof(struct PoorlyAlignedData,c), offsetof(struct PoorlyAlignedData,u), offsetof(struct PoorlyAlignedData,d), offsetof(struct PoorlyAlignedData,i), sizeof(PoorlyAlignedData));
printf("WellAlignedData d:%lu u:%lu i:%lu c:%lu size:%lu\n",
offsetof(struct WellAlignedData,d), offsetof(struct WellAlignedData,u), offsetof(struct WellAlignedData,i), offsetof(struct WellAlignedData,c), sizeof(WellAlignedData));
printf("PackedData d:%lu u:%lu i:%lu c:%lu size:%lu\n",
offsetof(struct PackedData,d), offsetof(struct PackedData,u), offsetof(struct PackedData,i), offsetof(struct PackedData,c), sizeof(PackedData));
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wenqzheng/Building-Low-Latency-Applications-with-CPP.git
git@gitee.com:wenqzheng/Building-Low-Latency-Applications-with-CPP.git
wenqzheng
Building-Low-Latency-Applications-with-CPP
Building-Low-Latency-Applications-with-CPP
main

搜索帮助