Efficient detection of signed overflow?
Andrew Haley
aph@redhat.com
Sat Dec 5 14:35:00 GMT 2009
Segher Boessenkool wrote:
>>>> The comment is wrong. The code checks for signed overflow, but the
>>>> following assignment still overflwos when ux is larger than INT_MAX.
>>> No, it doesn't. This conversion is implementation-defined (6.3.1.3/3),
>>> and GCC does the obvious two's complement thing. This code is fine.
>> It's fine with GCC 4.4, and likely with GCC 4.5 as well. But what
>> about GCC 4.6? And how will a user compiling third-party software
>> notice the discrepancy (if it ever arises)?
>
> Implementation-defined means the implementation defines
> the behaviour, and GCC defines it like this:
We know, we already discussed this upthread. The question is not
whether it works, but how to do it portably, not just for gcc.
Depending on 2's complement is fine, but depending on a particular
compiler is less so.
Andrew.
More information about the Gcc-help
mailing list