On 01/24/2013 03:33 PM, Jeffrey Walton wrote:
> On Thu, Jan 24, 2013 at 10:06 AM, Robert Dewar <de...@adacore.com> wrote:
> 
>> This is truly undefined, not implementation defined, and
>> if your program has such an overflow, you cannot assume
>> ANYTHING about the generated code.
> Signed integers that suffer overflow are operating in "undefined"
> behavior territory. Does the C/C++ standard specify what to do in this
> case?

No.  As the saying does, demons might fly out of your nose.

> Currently, I believe GCC removes the code rather than performing
> the operation or failing the compile.
> 
> Unsigned integers that wrap/carry enjoy "implementation defined"
> behavior. The GCC maintainers are free to do what they want with
> "implementation defined."

No, unsigned integers must wrap around.

A computation involving unsigned operands can never overflow, because a
result that cannot be represented by the resulting unsigned integer
type is reduced modulo the number that is one greater than the largest
value that can be represented by the resulting type.

Andrew.

Reply via email to