![]() |
![]() |
2852 | ![]() |
||||
![]() | |||||||
| Conversion to signed | |||||||
An apparent anomaly has been detected. Preceding operations imply that it will sometimes be impossible to represent the value of this expression in the signed type to which it is being converted. The result will be implementation-defined. For example, in the code shown below, the relational expression in the "if" statement implies that the value of
sia is expected to exceed 127 - sometimes. If the size of a char is 8 bits, values of this magnitude cannot be represented. Of course, if the value of sia never exceeds 127, the conversion will preserve the value; but this would imply that the "if" statement is redundant and any code contained in the "if" block is also redundant.
/*PRQA S 272,2017,2983,2986,3120,3195,3199,3203,3227,3408,3602 ++*/
void foo(signed int sia)
{
signed char sca;
if (sia > 127)
{
/* ... */
}
/* ... */
sca = sia; /* 2852 3756 */
}
MISRA-C:2004 Rules applicable to message 2852:
| 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 |