MISRA C:2012 Rule 10.7
If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential type
Description
Note
Using Code Prover for checking coding rules is no longer supported. See Version History.
Rule Definition
If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed, then the other operand shall not have 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 (
?
,:
)
Restricting implicit conversion on composite expressions mean that sequences of arithmetic operations within expressions must use the same essential type. This restriction reduces confusion and avoids loss of value, sign, precision, or layout. However, this rule does not imply that all operands in an expression are of the same essential type.
Performing arithmetic operation between essentially real floating types and essentially complex floating types does not violate this rule.
For more information on essential types, see Essential Types in MISRA C Rules 10.x.
Polyspace Implementation
Polyspace® reports a violation of this rule if an operand in a composite expression is implicitly converted to a wider essential type.
Polyspace does not report violations of this rule for pointer arithmetic and for conversions between essentially real floating type and essentially complex floating type.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: The Essential Type Model |
Category: Required |
AGC Category: Advisory |