I was reading the C Standard the other day, and noticed that unlike signed integer overflow (which is undefined), unsigned integer overflow is well defined. I\'ve seen it us
It's fine to rely on overflow as long as you know WHEN it will occur ...
I, for example, had troubles with C implementation of MD5 when migrating to a more recent compiler... The code did expect overflow but it also expected 32 bits ints.
With 64 bits the results were wrong !
Fortunately that's what automated tests are for : I caught the problem early but this could have been a real horror story if gone unnoticed.
You could argue "but this happens rarely" : yes but that's what makes it even more dangerous ! When there is a bug, everybody is suspicious of code written in the last few days. No one is suspicious f code that "just worked for years" and usually no one still knows how it works...