3 ms·
You think negative numbers in a signed type are a 1-in-a-1000 case, really? Silently casting signed integers to unsigned is a terrible idea, and a recipe for b
by adwn 4y ago
You think negative numbers in a signed type are a 1-in-a-1000 case, really?
Silently casting signed integers to unsigned is a terrible idea, and a recipe for bugs. And completely unnecessary to boot, because you could promote Int8 to Int16, and (Int16, UInt16) to (Int32, Int32).
- astrange 4y agoRelated, an integer bug that can't be fixed in C is that "unsigned short" promotes to "int" instead of "unsigned int", so this doesn't produce the result you want. unsigned x = (unsigned short)65535 * (unsigned short)65535; (It overflows even though it's less than UINT_MAX, and worse it's UB.)