3 ms·
> Some UB in C is largely regarded as a bad idea, such as signed overflow. I don't see why it's so bad. I've never really seen a legitimate use for signed ove
by clarry 8y ago
> Some UB in C is largely regarded as a bad idea, such as signed overflow.
I don't see why it's so bad. I've never really seen a legitimate use for signed overflow, and if it happens, the code is likely buggy anyway.
"I don't know how to properly check overflows so I'm just going to look and see if the number has wrapped" isn't really a good excuse, even if a few people fall for that trap. If anything, I'd rather see a simple, standard way for checking arithmetic introduced.
- kqr 8y agoIt sounds like you are under the impression that UB simply means you can't trust signed integers to wrap. Unfortunately, it is worse than that; under surprisingly normal-looking conditions, it is not unheard of that the compiler optimises an interation check away and replaces it with constant true or false, depending on what makes the underlying internal represenation neater. That's way beyond "can't do X"; it's "the meaning of your program suddenly ceases to exist".