MISRA C:2012 Rule 10.4
Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category
描述
规则定义
Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category 1 .
Polyspace 实现
如果某个运算的两个操作数具有不同的基本类型,则检查项会报告违反了此规则。检查项消息会指出在运算的两端检测到的类型。
如果其中一个操作数是常数零,则检查项不会报告违反了此规则。
如果某个运算的操作数中有一个是无符号整数,另一个是有符号整数常量,当该有符号常量与其等效的无符号变量具有相同的二进制表示形式时,Polyspace® 不会报告违规。例如,在这段代码中,Polyspace 假设表达式 (var + 1) 的类型本质上是无符号整数,因为 1 和 1U 具有相同的二进制表示形式:
unsigned int var;
int signed_var = (int) (var + 1);
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:基本类型模型 |
| 类别:必需 |
| 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.