Unsigned integer arithmetic has no undefined behavior on overflow. You can add, subtract, and multiply unsigned integers to your heart’s content! (Unfortunately, dividing by zero still causes undefined behavior.) This makes undefined integers safer for many purposes.
Is there any optimization-related reason why we might prefer to use integers
in loop indexes nevertheless? (You may want to examine the ubunsignedloop
program’s instructions using objdump --disassemble=loop -C
.)