结构体位域与规范定义顺序的问题
位域的规范定义如下
| bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 |
|地址类型 | 逻辑地址 |地址长度N |
结构体正确定义如下
typedef struct
{
uint8_t AddrLen:4;
uint8_t LogicAddr:2;
uint8_t ServerAddrType:2;
}SA;
错误定义如下:
typedef struct
{
uint8_t ServerAddrType:2;
uint8_t LogicAddr:2;
uint8_t AddrLen:4;
}SA;
typedef struct
{
uint8_t head;
uint16_t len;
uint8_t control;
SA ServerAddr;
uint8_t data[];
}FRAME_698;