We've optimized expressions such as (a*2)/2 on the basis of overflow being undefined for a very long time, not just loops.

What is (a*2)/2 optimized to? certainly it has the value a if you wrap, so you are not necessarily depending on undefined here.

No, it has not. For example, if a is 0x40000000 in a 32 bit type and arithmetic wraps, a*2 = -0x80000000 (overflow), and hence (a*2)/2 = -0x40000000 = -1073741824.

Paolo

Reply via email to