I need to know if intmax_t
is always "the same type" as uintmax_t
except using two's complement instead of unsigned value.
Or putting this in formal terms, will the code below always compile in a standard-compliant compiler?
#include <cstdint>
// The important assertion:
static_assert(sizeof(std::uintmax_t) == sizeof(std::intmax_t));
// Less important assertions:
static_assert(UINTMAX_MAX == static_cast<std::uintmax_t>(INTMAX_MAX) * 2 + 1);
static_assert(-static_cast<std::intmax_t>(UINTMAX_MAX / 2) - 1 == INTMAX_MIN);
I'm particularly interested in C++17.
I know that C++20 is the first version of the standard that enforces two's complement but the size of the variable is more important to me than the representation.