Skip to content

Latest commit

 

History

History
37 lines (30 loc) · 1014 Bytes

c26454.md

File metadata and controls

37 lines (30 loc) · 1014 Bytes
description title keywords ms.date ms.topic f1_keywords helpviewer_keywords dev_langs
Learn more about: Arithmetic overflow: '%operator%' operation produces a negative unsigned result at compile time
C26454
C26454
01/08/2017
reference
C26454
C26454
C++

Arithmetic overflow: '%operator%' operation produces a negative unsigned result at compile time

This warning indicates that the subtraction operation produces a negative result which was evaluated in an unsigned context. This can result in unintended overflows.

Example

unsigned int negativeunsigned()
{
    const unsigned int x = 1u - 2u; // C26454 reported here
    return x;
}

To correct this warning, use the following code:

unsigned int negativeunsigned()
{
    const unsigned int x = 4294967295; // OK
    return x;
}

See also

ES.106: Don't try to avoid negative values by using unsigned