4 ms·
So do signed types (guaranteed to be 2's complement since C23, though all sane targets have been using that representation for a long time). Two's complement e
by TuxSH 1y ago
So do signed types (guaranteed to be 2's complement since C23, though all sane targets have been using that representation for a long time).
Two's complement encodes -x as ~x + 1 = 2^n - x = -x (mod 2^n) and can therefore be mixed with unsigned for (+, -, *, &, |, ^, ~, <<).
> I think they should be used exclusively when this is needed
The opposite: signed type usage should be kept to a minimum because signed type (and pointer) overflow is UB and will get optimized as such.
- deleted 1y ago[deleted]
- uecker 1y agoFor signed types you can can also get a run-time trap on overflow, making it safe to use. Bug caused by unsigned wraparound are extremely hard to find.