I am using Visual Studio 2019 Community edition. I have the following C++ code snippet:
long long l = 0x80000000;
assert(l > 0); //true
l = -0x7fffffff;
assert(l < 0); // true
l = -0x80000000;
assert(l < 0); // FALSE
I expect -0x80000000 to end up sign-extended to 64-bit value of 0xFFFFFFFF80000000 but it doesn't. Instead it carries the positive 0x80000000 value. What do I miss?
There are rules for integral literals without suffixes.
In short,
0x80000000's type isunsigned intbecause it's an hexadecimal number bigger thanint's max value. In order to make it long long, you must add theLLsuffix, i.e.0x80000000LL.