Can’t Assign 64 Bit Number to 64 Bit Min in C++

This is exactly why the INT_MIN family of macros are often defined like -INT_MAX - 1 on a 2’s complement platform (virtually ubiquitous and compulsory from C++20).

There is no such thing as a negative literal in C++: just the unary negation of a positive number which produces a compile time evaluable constant expression.

9223372036854775808 is too big to fit into a 64 bit signed integral type, so the behavior of negating this and assigning to a signed 64 bit integral type is implementation defined.

Writing -9223372036854775807 - 1 is probably what your C++ standard library implementation does. If I were you, I’d use INT64_MIN directly or std::numeric_limits<std::int64_t>::min().

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top