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

推荐订阅源

罗磊的独立博客
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
量子位
博客园 - 三生石上(FineUI控件)
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
V2EX
人人都是产品经理
人人都是产品经理
V
Visual Studio Blog
Jina AI
Jina AI
L
LangChain Blog
M
MIT News - Artificial intelligence
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学

博客园 - 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.