Allowing signed integer overflows in C/C++
I want signed integers to overflow when they become too big. How do I achieve that without using the next biggest datatype (or when I am already at int128_t)? For example using 8bit integers 19*12 is commonly 260, but I want the result 1 11 10 01 00 with the 9th bit cut off, thus -27. Signed overflow is undefined in C, and that's for real . One solution follows: signed_result = (unsigned int)one_argument + (unsigned int)other_argument; The above solution involves implementation-defined behavior in the final conversion from unsigned to int but do not invoke undefined behavior. With most