konvertierung ints
-
wie siehts aus wenn man einen zu großen wert in einen kleinen datentypen casten will? oder einen mit vorzeichen? ist das ub / implementation defined / well formed?
auto a = (std::uint32_t)~std::uint64_t(); auto b = (std::uint32_t)-1; auto c = (std::uint32_t)std::numeric_limits<std::int64_t>::min();
-
für unsigned sind over- und underflow definiert.
also 2. ist 100%ig well formed1. auch well formed (~unit32_t)
3. impl. defined
-
§4.7/2(/3) schrieb:
If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo where n is the number of bits used to represent the unsigned type). [...]
If the destination type is signed, the value is unchanged if it can be represented in the destination type (and bit-field width); otherwise, the value is implementation-defined.