0X80000000 - 10 < 0 and 10 - 0X80000000 < 0
gcc version 3.3.4 gets a right result of comparing between 10 and 0X80000000,
but gcc version 4.1.0 fails.
the test code followed:
#include <stdio.h>
int main()
{
int b = 0X80000000;
if ((10 - b) < 0)
{
printf("(10 - b) = %d < 0 is True\n", 10 - b);
}
else
{
printf("(10 - b) = %d < 0 is False\n", 10 - b);
}
if ((b - 10) < 0)
{
printf("(b - 10) = %d < 0 is True\n", b - 10);
}
else
{
printf("(b - 10) = %d < 0 is False\n", b - 10);
}
return 0;
}
I had tested the code and got the result:
[EMAIL PROTECTED]:~/tmp> ../bin/g++ t.cpp
[EMAIL PROTECTED]:~/tmp> a.out
(10 - b) = -2147483638 < 0 is True
(b - 10) = 2147483638 < 0 is True
--
Summary: Error integer compare in g++ 4.1.0
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: johnzhang at tencent dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27257