4 ms·
> 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 yo
by oasisaimlessly 5mo ago
> 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().
- Groxx 5mo agoWhich makes them even less safe than unsigned, where it is defined, yes? The optimizations that can lead to are incredibly hard to predict. Besides, for safety there are much clearer options, like wrapping_add / saturating_add. Aborting is great as a safety tool though, agreed - it'd be nice if more code used it.
- uecker 5mo agoYou can have the trap during production, and then it is safer. If you need to catch the problem at run-time, there are checked integer options in C that you can use.