3 ms·
Integer overflow is usually logic error, so a reasonable default behavior would be a trap instead of silent overflow (regardless of how signed integrers are sto
by zajio1am 5y ago
Integer overflow is usually logic error, so a reasonable default behavior would be a trap instead of silent overflow (regardless of how signed integrers are stored in memory). Some architectures support that (e.g. MIPS).
- WalterBright 5y agoThe article mentions cases where integer overflow is expected behavior.
- zajio1am 5y agoC already offers 'unsigned' type variants that offers defined overflow (together with non-negative range). It would be useful to have another type variant that offers defined overflow (like in unsigned) together with signed range for such cases. But it still makes sense for basic integers to have overflow as UD, as in most cases it is not expected behavior. Note that in current C, if one needs defined overflow on signed integers, one can cast them to unsigned, to the operation and cast result back to int. That makes it implementation-defined instead of undefined.
- WalterBright 5y ago> as in most cases it is not expected behavior Yeah, but the gotcha happens when it is expected behavior.
- nwmcsween 5y ago-fsanitize-undefined-trap-on-error