News for hackers. Stuff that matters.
Re:Almost Always Unsigned by spacechild1 on Sunday January 02, 2022 @09:17AM (#29768837)
> Integer overflows are so rare that I can't even remember one happening with 64-bit values. Underflow on the other hand... I've encountered that plenty.

I totally agree!

After some horrible bugs caused by unsigned integers in innocent looking C/C++ code, I'm 100% in the signed camp. The only time I use unsigned is when I need well-defined overflow behavior (which is rare).

As a bonus, using signed loop counters in C/C++ code enables certain kinds of compiler optimizations (based on the fact that signed integer overflow is undefined behavior): http://blog.llvm.org/2011/05/what-every-c-programmer-should-...

Re:Almost Always Unsigned by cwzwarich on Sunday January 02, 2022 @12:04PM (#29770544)
The loop optimization you point to can be done for unsigned loop counters even without exploiting undefined behavior. It’s part not why the standard C practice was to use unsigned loop counters.