Hello!
Execute these lines:
int x = 1;
x = x > 2345678901;
You will get:
x == 1 with Borland C++ Builder
x == 0 with Microsoft Visual Studio
"int" is 32 bit in both compilers.
So the result should be the same.
Is this a bug in the Borland compiler?
Greetings,
Markus Sandheide
Mike Whaler has it mostly right, and quite a few other people have it
wrong.
A decimal literal without a suffix indicating that it is unsigned
NEVER becomes an unsigned type in either C or C++.
In C++, the type of a decimal literal is int if its value is within
the range of signed int. It its value is outside the range of signed
int, it has type signed long if it is within the range of signed long.
2345678901 is greater than INT_MAX for a 32-bit 2's complement signed
int. But since both the compilers you use have 32-bit 2's complement
signed long, it also outside the range of values for signed long. So
the result is undefined behavior.
Note that if compiled and executed this program on a platform where
int has 32 bits and long has 64 bits, such as 64 bit Windows and
perhaps some others, then the literal would easily fit into a signed
long. In the comparison 'x' would get promoted to signed long and the
result would be false.
Since you are not using an implementation where signed int or signed
long has more than 32-bits, neither compiler is right or wrong as far
as the language is concerned. There is no right or wrong once you
produce undefined behavior.