Synopsis: | Unary minus shall not be applied to an unsigned expression. |
Language: | C |
Severity Level: | 3 |
Category: | EXPRESSIONS |
Description: |
Unary minus acting on an unsigned expression gives an unsigned result which is never negative.
Example: Note that the negative is taken after any necessary promotions have been applied to the operand. Hence, the same problem could occur for an unsigned short provided short and int were the same size, causing a promotion from unsigned short to unsigned int rather than signed int. This however will not be the case for any PMS development.long j; unsigned int i = 1; ... j = (-i); /* j = (UINT_MAX - i) |