3 ms·
> But writing C code without undefined behavior, and avoiding its numerous pitfalls is absolutely necessary. I rarely (as in unicorns) see C code that consiste
by humanrebar 12y ago
> But writing C code without undefined behavior, and avoiding its numerous pitfalls is absolutely necessary.
I rarely (as in unicorns) see C code that consistently checks for unsigned integer overflow. Or signed integer overflow for that matter, but that's defined behavior.
Point being, I also encourage people to avoid undefined behavior, but whether and how one does that has subtleties in practice.
- FreeFull 12y agoUnsigned overflow is defined, signed overflow isn't.
- barrkel 12y agoSigned overflow is undefined, unsigned overflow is defined. But I agree with you. Not enough people take integer overflow seriously. Unsigned underflow, perfectly well defined behaviour, is actually a worse problem in practice, IMO. I think too many C programers think about unsigned types like they're a bounded type, e.g. they think "this variable can never be negative, therefore I'll give it an unsigned type". But unsigned types have a cliff of surprising behaviour right where they're commonly used - most integer values in programs are low. Whereas you really need to work on a signed value to get it to overflow.