|
|
A prvalue of an integer type or of an unscoped (since C++11) enumeration type can be converted to any other integer type. If the conversion is listed under integral promotions, it is a promotion and not a conversion. If the destination type is unsigned, the resulting value is the smallest unsigned value equal to the source value modulo 2n where n is the number of bits used to represent the destination type. That is, depending on whether the destination type is wider or narrower, signed integers are sign-extended or truncated and unsigned integers are zero-extended or truncated respectively. If the destination type is signed, the value does not change if the source integer can be represented in the destination type. Otherwise the result is . implementation-defined (until C++20) . the unique value of the destination type equal to the source value modulo 2n where n is the number of bits used to represent the destination type. (since C++20). https://en.cppreference.com/w/cpp/language/implicit_conversion#Integral_conversions |