Since C++20 two's complement representation is the only representation allowed by the standard, with the guaranteed range from -2N-1 to +2N-1-1. So for a 64-bit signed integer type the range goes from -9'223'372'036'854'775'808
to 9'223'372'036'854'775'807
. However, this code does not compile on Visual Studio (and neither on gcc)
int main()
{
long long x{-9'223'372'036'854'775'808LL};
// error C4146: unary minus operator applied to unsigned type, result still unsigned
// error C2397: conversion from 'unsigned __int64' to '__int64' requires a narrowing conversion
}
Yet, if I replace the code with long long x{-9'223'372'036'854'775'807LL - 1}
compiles just fine and x
holds the correct value. What am I not getting here?