3 ms·
Use `unsigned int` instead of `int` Overflow for signed types is undefined behavior. Hence the compiler can trap when it happens and remain standards compliant
by rocqua 6y ago
Use `unsigned int` instead of `int`
Overflow for signed types is undefined behavior. Hence the compiler can trap when it happens and remain standards compliant.
For unsigned types, overflow is defined behavior, and hence -ftrap will not trigger on overflow.
An interesting flip side of this is that using signed types can be a lot faster because the compiler is allowed to assume that overflow will not happen, which lets it apply more optimizations.