MISRAC2004-10.3
In this section:
Synopsis
(Required) The value of a complex expression of integer type shall only be cast to a type that is not wider and of the same signedness as the underlying type of the expression.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
A complex expression of integer type was found that is cast to a wider or differently signed underlying type.
Coding standards
- MISRA C:2004 10.3
(Required) The value of a complex expression of integer type shall only be cast to a type that is not wider and of the same signedness as the underlying type of the expression.
Code examples
The following code example fails the check and will give a warning:
void example(void) {
int s16a = 3;
int s16b = 3;
// arithmetic makes it a complex expression
long long x = (long long)(s16a + s16b);
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int array[10];
// A non complex expression is considered safe
long x = (long)(array[5]);
}