[previous] 2890 [next] Constant: Negative value implicitly converted to an unsigned type.
Conversion to unsigned

A constant expression with negative value is being implicitly converted to an unsigned type. Is this really intended ? The operation is well defined but is likely at best to be confusing.

The unsigned value which results will be the value obtained by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.

For example, in the following code, if char is an 8 bit type, the value assigned to ucx will be 255.


/*PRQA S 277,2017,3211,3408 ++*/

    unsigned char ucx = -1;             /* 2890 */


See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents