C1853: Unary minus operator applied to unsigned type

[DISABLE, INFORMATION, WARNING , ERROR]

Description

The unary minus operator was applied to an unsigned type.

Example
  void main(void) {

  
    unsigned char c;

  
    unsigned char d= -c;

  
  }

  
Tips

An unsigned type never can become a negative value. So using the unary minus operator may cause an unwanted behavior! Note that ANSI C treats -1 as negated value of 1. Therefore 2147483648 is an unsigned int, if int is 32 bits large or an unsigned long if not. The negation is a unary function as any other, so the result type is the argument type propagated to int, if smaller. Note that the value -2147483648 is the negation of 2147483648 and therefore also of a unsigned type, even if the signed representation contains this value.