写代码的时候,enum我们当然时经常使用,但是常常很多人没有注意到类型的问题,enum是个常量类型,不能与其他类型直接作比较或计算。
参考代码如下:
typedef enum{
part1 = 0x00,
part2 = 0x01,
part3 = 0x02,
part4 = 0x03,
}test;
test aaa ;
aaa = 0x00; /*错误,enum常量是part1-part4*/
aaa = (test)0x00; /*enum不能强转*/
uint8 u8_type = aaa;