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

Rule:  6.5.3.3.bChecked automatically with code checker

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.