C++ #pragma pack(n)

Set structure, union, and class member variables to be aligned with n bytes

#pragma pack(n) 使用
#pragma pack(push)  // 保存对齐状态
#pragma pack(4)     // 设定为 4 字节对齐
struct test
{
    
    
    char m1;
    double m4;
    int m3;
};
#pragma pack(pop)   // 恢复对齐状态
typedef struct {
    
    
    unsigned char prior;  /* 优先级 */
}__attribute__((packed))  USER_SETTING;

Guess you like

Origin blog.csdn.net/it_xiangqiang/article/details/112916524