Mingw-gcc结构体取消对齐
2014-03-28 14:56
543 查看
在gcc中,一般是可以通过__attribute__((packed))属性来取消对齐的,昨天在写个小工具是发现在使用code::block+mingw-gcc时却是死活不行了,无奈之下,只有在虚拟机里面使用gcc编译了。
今天差不多忙完了,来查查原因来了,原来MinGW-GCC是默认启动了兼容MS的特性的,
相关的GCC的说明查看http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
摘抄如下
所以在MinGW-GCC中,在用于结构体的对齐时,应该添加的__attribute__((gcc_struct, packed)) 。
今天差不多忙完了,来查查原因来了,原来MinGW-GCC是默认启动了兼容MS的特性的,
相关的GCC的说明查看http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
摘抄如下
Two attributes are currently defined for i386 configurations: ms_struct and gcc_struct. ms_struct gcc_struct If packed is used on a structure, or if bit-fields are used it may be that the Microsoft ABI packs them differently than GCC normally packs them. Particularly when moving packed data between functions compiled with GCC and the native Microsoft compiler (either via function call or as data in a file), it may be necessary to access either format. Currently -m[no-]ms-bitfields is provided for the Microsoft Windows X86 compilers to match the native Microsoft compiler.
所以在MinGW-GCC中,在用于结构体的对齐时,应该添加的__attribute__((gcc_struct, packed)) 。
相关文章推荐
- gcc 中的"__attribute__ ((packed))" gcc移植,内存对齐.结构体对齐-转
- 结构体字节对齐和位域对齐——VC、gcc
- gcc 中的"__attribute__ ((packed))" gcc移植,内存对齐.结构体对齐
- 字节对齐《c和指针》笔记--包含位域结构体的内存对齐(32bit,GCC)
- 结构体字节对齐和位域对齐——VC、gcc
- Arm结构体gcc内存边界对齐问题(zt)
- VC和gcc下的结构体字节对齐和位域对齐
- 结构体字节对齐和位域对齐——VC、gcc
- gcc 中结构体(struct)内存对齐问题分析
- vc下和gcc的结构体紧凑对齐格式存储【#pragma pack(push,1)、__attribute__ ((packed, aligned(1)))】
- 结构体字节对齐和位域对齐——VC、gcc
- 结构体字节对齐的规则
- C语言结构体的字节对齐方式
- sizeof()结构体对齐
- 结构体内存对齐与位域
- 使用gcc中的__attribute__指定字节对齐
- Linux下关于结构体对齐的总结
- c语言学习零碎整理(2):结构体对齐问题
- 联合体,位域, 结构体对齐
- [转]C语言结构体对齐