举个很简单的例子:
typedef struct
{
uint32_t magic;
uint64_t create_time;
uint8_t sample_rate;
uint8_t mark;
uint16_t head_type;
uint32_t reserved1;
uint64_t reserved2;
} raw_ecg_object_header_t;
这是一个28字节长度的结构体,如果使用sizeof(raw_ecg_object_header_t),则结果为32
__packed typedef struct
{
uint32_t magic;
uint64_t create_time;
uint8_t sample_rate;
uint8_t mark;
uint16_t head_type;
uint32_t reserved1;
uint64_t reserved2;
} raw_ecg_object_header_t;
如果在前面加上一个_packed,作用是字节对齐,则结果为28