TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - C Coding Standard
Search

SR:  7.4.5#1Checked automatically with code checker

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:

long j;
unsigned int i = 1;
...
j = (-i); /* j = (UINT_MAX - i)
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.