Specification C89:
The type of an integer constant is the first of the corresponding list in which its value can be represented. Unsuffixed decimal: int , long int , unsigned long int ; [...]
Thus, the literal type 2147483648 depends on the size of int , long and unsigned long respectively. Suppose int is 32 bits, like on many platforms (and this probably applies to your platforms).
On a 32-bit platform, 32 bits are typically used for long . So type 2147483648 will be unsigned long .
On a 64-bit platform, typically long should have 64 bits (although some platforms, such as MSVC, will still use 32 bits for long ). So type 2147483648 will be long .
This leads to the mismatch that you see. In one case, you negate the unsigned long , and in the other case you negate the long .
On a 32-bit platform, -2147483648 is evaluated as 2147483648 (using the unsigned long type). Thus, the comparison obtained is 2147483648 < 2147483647 , which is evaluated as 0 .
On a 64-bit platform, -2147483648 is evaluated to -2147483648 (using the long type). Thus, the comparison obtained is -2147483648 < 2147483647 , which is evaluated as 1 .
Cornstalks
source share