[previous] 2895 [next] Constant: Negative value cast to an unsigned type.
Conversion to unsigned

A constant expression with negative value is being cast 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 the 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, if char is an 8 bit type, the value assigned to ucx will be 255.


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

    unsigned char ucx = (unsigned char)-1;             /* 2895 */


See also:

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