No Memory Alignment with GCC
来源:互联网 发布:js代码提取网页信息 编辑:程序博客网 时间:2024/06/06 19:09
attribute
method:#include <stdio.h>struct packed{ char a; int b;} __attribute__((packed));struct not_packed{ char a; int b;};int main(void){ printf("Packed: %zu\n", sizeof(struct packed)); printf("Not Packed: %zu\n", sizeof(struct not_packed)); return 0;}
Output:
$ make example && ./examplecc example.c -o examplePacked: 5Not Packed: 8
pragma pack
method:#include <stdio.h>#pragma pack(1)struct packed{ char a; int b;};#pragma pack()struct not_packed{ char a; int b;};int main(void){ printf("Packed: %zu\n", sizeof(struct packed)); printf("Not Packed: %zu\n", sizeof(struct not_packed)); return 0;}
Output:
$ make example && ./examplecc example.c -o examplePacked: 5Not Packed: 8
Add
-fpack-struct
to GCC- -fpack-struct[=n]
- Without a value specified, pack all structure members together without holes. When a value is specified (which must be a small power of two), pack structuremembers according to this value, representing the maximum alignment (that is, objects with default alignment requirements larger than this will be outputpotentially unaligned at the next fitting location.
Warning: the -fpack-struct switch causes GCC to generate code that is not binary compatible with code generated without thatswitch. Additionally, it makes the code suboptimal. Use it to conform to a non-default application binary interface.
0 0
- No Memory Alignment with GCC
- memory alignment
- Memory Alignment
- Memory Alignment
- Memory Alignment
- 内存对齐(Memory Alignment)
- target: alignment with features
- GCC汇编源码中的alignment
- Android Memory Alignment: ARM vs. x86
- VC内存对齐准则(Memory alignment)
- VC内存对齐准则(Memory alignment)
- Game Server Programming : MemoryPool : Memory Alignment
- AAM Alignment最后一篇:Robust AAM Alignment with Occlusion
- Memory allocation with strings
- Playing with Virtual Memory
- Playing with Virtual Memory
- Getting Physical With Memory
- Getting Physical With Memory
- android 拍照剪切图片
- 漂亮的 PHP 验证码类
- Migrating to WebView in Android 4.4
- 如何实现struts2标签按钮并排显示
- java相关网络协议无响应
- No Memory Alignment with GCC
- 如何获取键盘的高度,而不需要通过通知?
- 前端架构那些事儿
- 炫耀贴, 更新近况!
- 查看各个表空间可以回收空间的脚本
- STL::map mutil_map unordered_map 小结
- Binary Tree Level Order Traversal II
- 心情日记
- Struts2+Hibernate整合应用开发步骤