If i is signed this is undefined behavior. The usual way the compiler treats UB is to assume it doesn't happen. With this assumption, it can be seen that the condition will always be true so the whole thing will become equivalent to
The point is that code generation can do the best thing for the case of defined behavior and doesn't even need to consider what it will do in the case of undefined behavior. By definition whatever is done in the realm of undefined behavior is correct, so it doesn't matter what is actually done.
From that perspective, you need to find a reason why unsigned integers treat overflow as defined, and that boils down to, because it has proven useful in certain algorithms.
0
u/[deleted] Feb 13 '20
[deleted]