惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
GbyAI
GbyAI
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
Visual Studio Blog
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
B
Blog
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
雷峰网
雷峰网
爱范儿
爱范儿
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
Jina AI
Jina AI
P
Proofpoint News Feed
A
About on SuperTechFans
I
InfoQ
F
Fortinet All Blogs
L
LangChain Blog
T
Tailwind CSS Blog

博客园 - fei

Revisit Plan9 Microsoft Windows Edit Control Messages A Day of Wasterful Efforts 疯狂出租车--完全攻略 All about I/O 显卡(转) 电脑主板硬件故障解析(转) 显卡性能指标(转) 主板问题介绍(转) 电脑黑屏故障(转) 硬件故障(转) 错误检测(转) TCP 长连接和短连接 Where does OSI model come from? A chance is missed! Why do things become this? Copy What you Like Setup VC Express Edition Stop Rewrite Code of LiSP
On #pragma pack()
fei · 2006-09-13 · via 博客园 - fei

#pragma  pack(n),  where  n  is  1,  2,  4,  8,  or  16:
each  structure  member  after  the  first  is  stored  on  the  smaller  member  type  or  n-byte  boundaries.

A example will give a more direct impression:

#pragma pack(8)
struct A {
    
char c;
    
int i;
};

so sizeof(A) is 8;
while

#pragma pack(1)
struct A {
    
char c;
    
int i;
};

then sizeof(A) is 5.


PS. There is a little funny when I first encounter this preprocessor. I guess pack(8) is to force to align at 8b, but in fact the true meaning is 8B.