Synopsis: | Unary minus shall only be applied to an operand having a signed arithmetic type. |
Language: | C |
Severity Level: | 1 |
Category: | Expressions |
Description: |
Justification Unary minus on an unsigned expression gives an unsigned result which is never negative; unary minus on a non-arithmetic expression is not allowed. Example long j; unsigned int i = 1; signed int k = 1; ... j = -i; /* WRONG: very large positive number */ j = -k; /* RIGHT */ Note The negative is taken after any necessary promotions have been applied to the operand. |