3 ms·
Didn't they specify two's complement signed integers somewhat recently? What's the rationale for leaving these behaviours undefined?
by rcfox 3y ago
Didn't they specify two's complement signed integers somewhat recently? What's the rationale for leaving these behaviours undefined?
- kazinator 3y agoBecause the shift operations are arithmetically defined, and the situations that are undefined correspond to overflow. v << 1 means the same thing as v * 2 and is undefined if v * 2 is undefined.
- Findecanor 3y agoOn some CPUs architectures, the operand size for some instructions could be larger than an `int`, in which case the upper part of a CPU register would become invalid on overflow instead of containing an extension of the sign bit. There are also CPUs that do "saturating arithmetic" where overflow results in INT_MAX instead of wrapping.