[previous] 2900 [next] Constant: Positive integer value truncated by implicit conversion to a smaller unsigned type.
Conversion to unsigned

The value of a non-negative integer constant expression is being implicitly converted to an unsigned type. The value of the expression is larger than the maximum value which can be represented in this type and so truncation will occur using modulo arithmetic.

For example:


/*PRQA S 1255,2017,3120,3211,3306,3408,3606 ++*/


unsigned char  uca = 255;                 /* OK   */
unsigned char  ucb = 256;                 /* 2900 */
unsigned short usa = 65535;               /* OK   */
unsigned short usb = 65536;               /* 2900 */


MISRA C:2012 Rules applicable to message 2900:

Rule-10.3  (Required) The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents