MISRA C:2012 Rule 10.6
The value of a composite expression shall not be assigned to an object with wider essential type
Description
Note
Using Code Prover for checking coding rules is no longer supported. See Version History.
Rule Definition
The value of a composite expression shall not be assigned to an object with wider essential type.
Rationale
A composite expression is a nonconstant expression using a composite operator. In the Essential Type Model, composite operators are:
Multiplicative (
*
,/
,%
)Additive (binary
+
, binary-
)Bitwise (
&
,|
,^
)Shift (
<<
,>>
)Conditional (
?
,:
)
Unary operators such as ~
and unary +
or -
are also considered composite operators.
If you assign the result of a composite expression to a larger type, the implicit conversion can result in loss of value, sign, precision, or layout.
For more information on essential types, see Essential Types in MISRA C Rules 10.x.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Check Information
Group: The Essential Type Model |
Category: Required |
AGC Category: Advisory |