On Wed, 8 Apr 2015 12:53:47 +0200, Joerg Arndt <arndt@jjj.de> wrote:
Don't essentially all existing platforms(*) just treat signed "int"s as what they are: fixed length registers? I know only of Itanium where overflow may trap (not even sure if it's the default there, at least I got no warnings and no traps the single time I used Itanium).
All *contemporary* existing platforms likely do. There used to be platforms where integers were essentially denormalized floating point numbers. A non-trapping integer overflow (yielding a normalized floating point number) would not be equal to any integer, and an attempt to perform bitwise Boolean operations on it would result in garbage. My understanding is that the proximate rationale for making integer overflow undefined behavior is DSP-like CPUs which might have saturating integer overflow by default; thus int a = 1; while (a != 0) a = a+1; is indeed an infinite loop. Teaching people not to use signed integers when they need modulo 2^w operations or bitmask manipulation is a good thing. Leo