Is it considered undefined behavior in C++ to cast between a uint8_t value and an int8_t value? For example consider this code:
std::uint8_t x = 255;
std::int8_t y = static_cast<int8_t>(x);
The goal with this casting is to interpret the value 11111111 (i.e., x=255) as a two's complement representation (i.e., y=-1). Is this valid in C++ or is it considered undefined behavior?
Aucun commentaire:
Enregistrer un commentaire