The video \"Gangnam Style\" (I\'m sure you\'ve heard it) just exceeded 2 billion views on youtube. In fact, Google says that they never expected a video to be greater than a 32-
This guideline is extremely misleading. Blindly using int
instead of unsigned int
won't solve anything. That simply shifts the problems somewhere else. You absolutely must be aware of integer overflow when doing arithmetic on fixed precision integers. If your code is written in a way that it does not handle integer overflow gracefully for some given inputs, then your code is broken regardless of whether you use signed
or unsigned int
s. With unsigned int
s you must be aware of integer underflow as well, and with double
s and float
s you must be aware of many additional issues with floating point arithmetic.
Just take this article about a bug in the standard Java binary search algorithm published by none other than Google for why you must be aware of integer overflow. In fact, that very article shows C++ code casting to unsigned int
in order to guarantee correct behavior. The article also starts out by presenting a bug in Java where guess what, they don't have unsigned int
. However, they still ran into a bug with integer overflow.