b******n 发帖数: 823 | 1 很简单的code,里面有这段
if (j+1 < u)
{
blabla...
}
从watch里面看到j+1是小于u的,但是就是不进这个if
结果改成这样就进去了
int tmp = j+1-u;
if (tmp < 0)
{
blabla...
}
有人知道是啥毛病么?用的VS2008,默认设置,optimization是disable的 |
X****r 发帖数: 3557 | 2 One possibility is that j is signed but u is unsigned.
When a binary operator has both signed and unsigned operands,
the signed integer is converted to unsigned according to
"usual arithmetic conversions". Thus the result of expression
-1 < 1u is false, while -1 < 1 is true. VC should have given
you a warning about mixing signed and unsigned, which you probably
have ignored.
【在 b******n 的大作中提到】 : 很简单的code,里面有这段 : if (j+1 < u) : { : blabla... : } : 从watch里面看到j+1是小于u的,但是就是不进这个if : 结果改成这样就进去了 : int tmp = j+1-u; : if (tmp < 0) : {
|
b******n 发帖数: 823 | 3 Thanks. But just checked, both are int...
【在 X****r 的大作中提到】 : One possibility is that j is signed but u is unsigned. : When a binary operator has both signed and unsigned operands, : the signed integer is converted to unsigned according to : "usual arithmetic conversions". Thus the result of expression : -1 < 1u is false, while -1 < 1 is true. VC should have given : you a warning about mixing signed and unsigned, which you probably : have ignored.
|
d****p 发帖数: 685 | 4 You may turn off optimization and try rebuild your program. |
l***g 发帖数: 1035 | 5 (j+1)
【在 b******n 的大作中提到】 : 很简单的code,里面有这段 : if (j+1 < u) : { : blabla... : } : 从watch里面看到j+1是小于u的,但是就是不进这个if : 结果改成这样就进去了 : int tmp = j+1-u; : if (tmp < 0) : {
|