|
发表于 2011-7-22 13:54:04
|
显示全部楼层
呵呵,兄弟,你确信enum的值域类型一定是整形吗?
特意针对你说的,我做了一个试验,不妨贴上来给你看看,我在展讯
平台上随意找了个地方测试的,ads编译,源码、log我都贴给你看看:
源码:
typedef enum
{
list_o,
list_1,
list_2,
list_max
}te_list;
te_list g_bDrvList1,g_bDrvList2;
int para = 0xffffffffffffffff;
SCI_TRACE_LOW("g_bDrvList1 = %d, g_bDrvList2 = %d, para = %d",
g_bDrvList1,g_bDrvList2,para);
g_bDrvList1 = 1.1;
g_bDrvList2 = para%list_max;
SCI_TRACE_LOW("g_bDrvList1 = %d, g_bDrvList2 = %d, para = %d",
g_bDrvList1,g_bDrvList2,para);
(char)para = 'a';
g_bDrvList1 = (te_list)para;
g_bDrvList2 = para%list_max;
SCI_TRACE_LOW("g_bDrvList1 = %d, g_bDrvList2 = %d, para = %d",
g_bDrvList1,g_bDrvList2,para);
编译运行结果没有报错,请思考为什么?同时,我也把log打印出来的
信息给你看看:
68-28:g_bDrvList1 = 19, g_bDrvList2 = 127, para = -1
68-29:g_bDrvList1 = 1, g_bDrvList2 = -1, para = -1
68-30:g_bDrvList1 = 1644167167, g_bDrvList2 = 1, para = 1644167167
至于为什么,我不再分析,看过思考下就明白的。
然后我又做了一次改变针对上面的两点,看它的值域是不是所说的接近
整形的数值,上述的源码,我只改了两个地方:
g_bDrvList1 = 1.6; //第一次是1.1 打印出来是1,因为我用的是%d
SCI_TRACE_LOW("g_bDrvList1 = %f, g_bDrvList2 = %d, para = %d",
g_bDrvList1,g_bDrvList2,para);
第二次我改用%f输出数据格式。
最后的打印结果:
68-5:g_bDrvList1 = 19, g_bDrvList2 = 127, para = -1
68-6:g_bDrvList1 = 0.000000, g_bDrvList2 = -1, para = 74
68-7:g_bDrvList1 = 1644167167, g_bDrvList2 = 1, para = 1644167167
看到了吧,呵呵,
倒是希望伊莉莎能看到,哈哈 |
|