【发布时间】:2016-06-06 08:01:45
【问题描述】:
typedef union {
struct {
union {
struct {
unsigned int dev_t : 4; // Device Type, see DEV_type_t
unsigned int dev_n : 7; // Device Number
};
unsigned int id : 11; // CAN_ID
};
unsigned int online : 1;
unsigned int reserved : 4;
}; // 16 bit total
uint16_t _raw;
} CAN_prefix_t;
编译后sizeof(CAN_prefix_t)显示3 bytes,但预期为2 bytes(11+1+4 bits or 4+7+1+4 bits = 16 bits)。
谁能建议如何以正确的方式定义上面的结构/联合?
提前致谢!
【问题讨论】:
标签: sizeof unions bit-fields keil