3 ms·
The infinite loop on unsigned integers exemplifies a failure in C's type system: integer wraparound is so rarely desirable behavior that a range error on wrapar
by iamsohungry 11y ago
The infinite loop on unsigned integers exemplifies a failure in C's type system: integer wraparound is so rarely desirable behavior that a range error on wraparound would prevent many such errors from failing silently.
There's an argument to be made that this check would hurt performance (and I buy that argument--given C's goals and the time when it was made, the type system compromises it made make sense). But it would be nice if processor manufacturers made add/sub instructions that detected wraparound, which would allow languages to implement such checks performantly.
- scj 11y agoThe overflow flag is what you're looking for.
- iamsohungry 11y agoBut checking this flag takes another instruction, no? I'm thinking more along the lines of some sort of interrupt being thrown automatically if the operation overflows.