条件评估为真,而调试器说它应该为假

标签 c debugging gdb

当我遇到这个奇怪的事情时,我正在 gdb 中调试:

(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++ bool 行为的枚举:

typedef enum { FALSE, TRUE } bool;

这怎么可能?

最佳答案

GDB 没有正确评估 sqrt,如下所示:Why does gdb evaluate sqrt(3) to 0?

关于条件评估为真,而调试器说它应该为假,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5115866/

相关文章:

python - 无法在共享对象库中插入断点 x,(python 使用来自 c++ 的 .so 库)

c++ new运算符通过libstdc++占用大量内存(67MB)

C 哈希表指针错误

c - 如何在 Xamarin.iOS 中正确包装 native c 库

gdb - 检查 GDB 中的函数返回值

python - 识别当前正在执行哪个函数调用

c - 替换文本中间的特定单词

c - Xcode 中缺少 c.h?

debugging - 如何在gdb中将命令的输出作为参数传递?

visual-studio-code - 无法从命令环境 cd 开始调试意外的 gdb 输出