我在gdb调试时,我碰到这个怪胎来了:条件计算为true,而调试器说,这应该是假
(gdb)
107 newIterationRequired = infoAvailableUntil+1 < sqrt(input)+1 && isPrime ? TRUE : FALSE;
(gdb)
107 newIterationRequired = infoAvailableUntil+1 < sqrt(input)+1 && isPrime ? TRUE : FALSE;
(gdb) print infoAvailableUntil+1 < sqrt(input)+1 && isPrime ? TRUE : FALSE
$11 = FALSE
(gdb) s
108 if (newIterationRequired)
(gdb) print newIterationRequired
$13 = TRUE
newIterationRequired
的类型是一个枚举,其模拟从C++布尔行为:
typedef enum { FALSE, TRUE } bool;
这怎么可能?
可读性建议:'值=条件? TRUE:FALSE;'与'value = condition;'相同(假设'TRUE'为1,'FALSE'为0,它们是)。 – Marlon 2011-02-25 10:04:43
这是在多线程环境中运行吗?你确定你没有跳过可能会改变'newIterationRequired'值的指令吗? – templatetypedef 2011-02-25 10:06:51
也许在C中的优先权不同于GDB? – rene 2011-02-25 10:08:23