由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 真是奇了怪了,VC编译器问题?
相关主题
0 < -1 ? A c++ questionc的小问题
一个integer promotion问题"(char *)-1" 是什么意思?
binary number questionC++隐式类型转换的规则?
C++: operator new 为啥要是 static的, 不是有啥影响?以下两个C 代码是不是完全等价?
小白一问:vista下面用什么C编译器?gcc 优化不优化运算结果不一样?gcc 的 bug?
32/64bit Fortran编译器造成的错误一道面试题
c++14出来了?unsigned 8bit integer转换成signed 16bit应该是什么结果?
Java的POD比C++干净很多更多的关于Java GC
相关话题的讨论汇总
话题: unsigned话题: vc话题: signed话题: tmp话题: blabla
进入Programming版参与讨论
1 (共1页)
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)
: {

1 (共1页)
进入Programming版参与讨论
相关主题
更多的关于Java GC小白一问:vista下面用什么C编译器?
int 和 unsigned int 比大小会出问题 c++32/64bit Fortran编译器造成的错误
a=b=0比a=0,b=0快c++14出来了?
conversion(c++)Java的POD比C++干净很多
0 < -1 ? A c++ questionc的小问题
一个integer promotion问题"(char *)-1" 是什么意思?
binary number questionC++隐式类型转换的规则?
C++: operator new 为啥要是 static的, 不是有啥影响?以下两个C 代码是不是完全等价?
相关话题的讨论汇总
话题: unsigned话题: vc话题: signed话题: tmp话题: blabla