__attribute_((packed))参数
来源:互联网 发布:淘宝童装店名大全 编辑:程序博客网 时间:2024/06/12 22:43
__attribute__((packed))的作用是让编译器取消结构体在编译过程中的优化对齐,可以保证结构体在不同的处理器中有相同的大小。使用示例:
typedef struct __attribute__((packed)) { uint8_t protocolType[12]; uint8_t packetType; uint8_t serviceType; uint8_t optRetCode; uint8_t reserved; uint32_t dataLen;} PktHeader;
下面用一个例子进行解释:
typedef struct { char aChar; int anInt ;} s;
假如处理器是使用八个字节进行优化对齐。那么aChar将占据第1个字节,紧跟的7个字节将不被使用,然后anInt将从第9个字节开始。
假如处理器是使用四个字节进行优化对齐,那么aChar将占据第1个字节,紧跟的4个字节将不被使用,然后anInt将从第5个字节开始。
如果使用了__attribute__((packed))
typedef struct __attribute__((packed)) { char aChar; int anInt ;} s;那么将强制让anInt紧跟在aChar后边,aChar占据第1个字节,而anInt从第2个字节开始。
0 0
- __attribute_((packed))参数
- __attribute_((packed))
- __attribute_((naked))
- GCC编译关键字“__attribute_…
- GCC编译关键字“__attribute_…
- Packed record
- _attribute_((packed))
- __attribute__ ((packed))
- __attribute__ ((packed))
- __attribute__ ((packed))
- _attribute_((packed))
- _attribute_((packed))
- _attribute_((packed))
- _attribute_((packed))
- __attribute__((packed))
- __attribute__((packed))
- __attribute__((packed))
- Packed Record
- 策略模式
- 文本编辑器 GUI IO编程
- Android SDK Manager软件包下载安装相关问题的解决办法
- Python运算符总结
- 冒泡排序
- __attribute_((packed))参数
- 网络协议笔记
- 制作uImage镜像 .
- AOJ661 跨越千山万水只为找到你
- eclipse导入系统签名
- 如何应用ul、li标签 创建css横向导航菜单?
- 博客开通
- C++ deque(double-ended-queue)双端队列
- ubuntu RPM should not be used directly install RPM packages, use Alien instead!