现在的位置: 首页 > 综合 > 正文

结构体指针,内容偏移

2018年05月11日 ⁄ 综合 ⁄ 共 405字 ⁄ 字号 评论关闭

结构体指针,默认会以4字节补齐?

指向的内容有偏移?

#pragma pack(1)
typedef struct LINKAGE {
    unsigned char source_device_id;
    unsigned char target_device_id;
    unsigned char source_device_type;
    unsigned char source_action;
    unsigned char target_device_type;
    unsigned char target_action;
    unsigned int  source_parameter;
    unsigned int  target_parameter;
    unsigned char status;
}LINKAGE;
#pragma pack()

在定义结构体的地方加

#pragma pack(1)
<pre name="code" class="objc">#pragma pack()
命令结构体以1字节补齐

抱歉!评论已关闭.