On Fri, 26 Jul 2013, Jason Merrill wrote:

On 07/26/2013 01:33 AM, Andrew Pinski wrote:
What does it mean by "unsigned-integer-overflow"? Unsigned integers
never overflow.

This is a common misconception. Conversion to an unsigned integer type never has undefined behavior, but unsigned integer arithmetic does. C11 says,

If an exceptional condition occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not in the range of representable values for its type), the behavior is undefined.

So UINT_MAX+1U has undefined behavior.

Uh?
C11 also says:

"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."

UINT_MAX+1U is mathematically well defined, it is 0U (modulo 2^N), which is in the range.


--
Marc Glisse

Reply via email to