It is indeed integer overflow, and an artefact of two's complement.
On your implementation, LLONG_MIN
is -9223372036854775808
which is 0x8000000000000000
in hexadecimal (I will be using this hexadecimal notation because it's easier to see what happens to the bits).
When you compute -LLONG_MIN
on a system that uses two's complement, under the hood you first make a bitwise-not (yielding 0x7FFFFFFFFFFFFFFF == LLONG_MAX
) then add 1 which overflows the signed integer and gives back 0x8000000000000000 == LLONG_MIN
.
Note that signed integer overflow is Undefined Behaviour, so there is no guarantee that it will behave consistently on every C++ implementation.