![]() |
![]() |
2857 | ![]() |
||||
![]() | |||||||
| Conversion to signed | |||||||
An apparent anomaly has been detected. An expression is being cast to a signed type, but examination of the context indicates that the value being converted will sometimes be unrepresentable in this type. The result will be implementation-defined. For example, an object of type signed char can usually only represent values in the range -128 to 127. In the code shown below, unless the
if statement is redundant, the code implies that the value of sia will sometimes exceed 127.
If it does, behaviour in the subsequent assignment operation will be implementation-defined.
/*PRQA S 273,1278,2017,2984,2983,2986,3120,3195,3198,3199,3203,3227,3408,3602 ++*/
void foo(signed int sia)
{
signed char sca;
if (sia > 200)
{
}
sca = (signed char)sia; /* 2857*/
}
MISRA C:2012 Rules applicable to message 2857:
| 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 |