| ▲ | Groxx 13 hours ago | |||||||
That's true for signed numbers too though? `int_min - 2 > int_min` I agree they're a bit more error-prone in practice, but I suspect a huge part of that is because people are so used to signed numbers because they're usually the default (and thus most examples assume signed, if they handle extreme values correctly at all (much example code does not)). And, legitimately, zero is a more commonly-encountered value... but that can push errors to occur sooner, which is generally a desirable thing. | ||||||||
| ▲ | pron 12 hours ago | parent | next [-] | |||||||
> That's true for signed numbers too though? `int_min - 2 > int_min` As someone else already pointed out, that's undefined behaviour in C and C++ (in Java they wrap), but the more important point is that the vast majority of integers used in programs are much closer to zero than to int_min/max. Sizes of buffers etc. tend to be particularly small. There are, of course, overflow problems with signed integers, but they're not as common. | ||||||||
| ▲ | oasisaimlessly 13 hours ago | parent | prev [-] | |||||||
> That's true for signed numbers too though? `int_min - 2 > int_min` No, that's undefined behavior in C, and if you care about correctness, you run at least your testsuite in CI with -ftrapv so it turns into an abort(). | ||||||||
| ||||||||