MISRAC2004-10.1_a
Synopsis
(Required) The value of an expression of integer type shall not be implicitly converted to a different underlying type if: (a) it is not a conversion to a wider integer type of the same signedness.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
An expression of integer type was found that is implicitly converted to a narrower or differently signed underlying type.
Coding standards
- MISRA C:2004 10.1
(Required) The value of an expression of integer type shall not be implicitly converted to a different underlying type if: a. it is not a conversion to a wider integer type of the same signedness, or b. the expression is complex, or c. the expression is not constant and is a function argument, or d. the expression is not constant and is a return expression.
Code examples
The following code example fails the check and will give a warning:
void example(void) {
long pc[10];
// integer narrowing from int -> short
short x = pc[5];
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int pc[10];
long x = pc[5];
}