Why does MSVC pick a long long as the type for -2147483648?

后端 未结 1 1901
难免孤独
难免孤独 2020-12-11 02:14

My snippet:

auto i = -2147483648;
int j = 3;
std::swap(i, j); // Compile error about mismatched types here. 

The compiler states that the l

相关标签:
1条回答
  • 2020-12-11 02:39

    Contrary to popular belief, -2147483648 is not a literal: C++ does not support negative literal values.

    It is, in fact, a compile-time evaluable constant expression consisting of a unary negation of the literal 2147483648.

    On MSVC x64, which has 32 bit ints and longs, 2147483648 is too big for either of those so it fails over to the long long type that you observe.

    0 讨论(0)
提交回复
热议问题