kiznit wrote:
C99 standard (§6.2.5/9) wrote:
A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.
You are right for unsigned integers. I didn't know / forgot about this. But is is undefined for signed integers:
C99 standard (§3.4.3/1) wrote:
An example of undefined behavior is the behavior on integer overflow
As to why that is, check this link:
http://stackoverflow.com/questions/1819 ... verflow-isInteresting comments, I hadn't thought of that before. Nevertheless I can find many "obscure" ways of representing unsigned integers, but there truly is only one system that's in common use and while there are multiple ways of representing signed integers that all allow the same range of numbers to be represented and that give similar performance, that is not true for unsigned integers as there is really only one system that *should* be used (ordinary binary).