4 ms·
Subtraction would presumably fall under the arithmetic behavior that OP was talking about.
by 10000truths 4y ago
Subtraction would presumably fall under the arithmetic behavior that OP was talking about.
- eru 4y agoMaybe. But subtraction is also perfectly well defined for unsigned ints in C.
- kcexn 4y agoIf you wanted to be extremely careful, you might pass unsigned ints into a function by copy, and cast it as a signed int to perform arithmetic, then do a boundary check before returning a result to be assigned back to an unsigned integer. The unsignedness of the integer lets readers of the code know that it's a constant of some kind, and that comparisons should be performed with care. Normally, when I've worked with C (fairly limited), unsigned numbers normally get used as flags for bitwise comparisons. Sometimes your flags may have a partial ordering defined on them (so a sense of flag A being 'smaller' than flag B), so you might need some arithmetic to do those checks you need to be explicitly careful with the boundary checks though.