|
|
|
|
|
by bringbart
253 days ago
|
|
>while unsigned wraparound leads to bugs which are basically impossible to find. What? unsigned sizes are way easier to check, you just need one invariant: if(x < capacity) // good to go Always works, regardless how x is calculated and you never have to worry about undefined behavior when computing x.
And the same invariant is used for forward and backward loops - some people bring up i >= 0 as a problem with unsigned, but that's because you should use i < n for backward loops as well, The One True Invariant. |
|