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
描述
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 1 .
理由
一个复合表达式是使用复合运算符的非常量表达式。在基本类型模型中,复合运算符包括:
乘法运算符(
*、/、%)加法运算符(二进制
+、二进制-)位运算符(
&、|、^)移位运算符(
<<、>>)条件运算符(
?、:)
限制复合表达式中的隐式转换意味着,表达式中的算术运算序列必须使用相同的基本类型。此限制可减少混淆,避免值、符号、精度或布局丢失。然而,这条规则并不意味着表达式中的所有操作数都属于同一基本类型。
在本质上为实数浮点的类型与本质上为复数浮点的类型之间执行算术运算并不违反此规则。
有关基本类型的详细信息,请参阅Essential Type Model Used in MISRA C Rule Checking。
Polyspace 实现
Polyspace® 报告复合表达式中的操作数被隐式转换为更宽的基本类型时,违反了此规则。
对于指针运算,以及本质上为实数浮点类型与本质上为复数浮点类型之间的转换,Polyspace 不会报告此规则的违规。
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:基本类型模型 |
| 类别:必需 |
| AGC 类别:建议 |
版本历史记录
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.