![]() |
![]() |
2895 | ![]() |
||||
![]() | |||||||
| 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 */
MISRA-C:2004 Rules applicable to message 2895:
| Rule 3.1 (Required) | All usage of implementation-defined behaviour shall be documented. |
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |