![]() |
![]() |
2890 | ![]() |
||||
![]() | |||||||
| 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 */
MISRA C:2012 Rules applicable to message 2890:
| Dir-1.1 (Required) | Any implementation-defined behaviour on which the output of the program depends shall be documented and understood |
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 |