|
|
|
|
|
by uecker
360 days ago
|
|
"Naturally, sizes should be unsigned because they represent values which cannot be unsigned." Unsigned types in C have modular arithmetic, I think they should be used exclusively when this is needed, or maybe if you absolutely need the full range. |
|
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.