MISRA C:2012 Rule 13.2
The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders and shall be independent from thread interleaving
描述
规则定义
The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders and shall be independent from thread interleaving 1 .
理由
如果表达式的值因评估顺序而异,则其值为实现定义。
如果表达式根据线程交错顺序产生不同的值,则该值是不可预测的,因为 C 标准未指定线程交错顺序。这种不可预测的行为意味着您的代码可能包含数据争用条件,这是未定义的行为。
Polyspace 实现
如果表达式满足以下任何条件,规则检查器将报告违规:
同一个变量在表达式中被修改了多次,或者它既被读取又被写入。
该表达式允许多个求值顺序。
该表达式包含一个多次出现的单个
volatile
对象。表达式中包含多个
volatile
对象。
由于 volatile
对象可以随时更改其值,因此包含多个 volatile
变量或多个相同 volatile
变量的表达式可能会根据评估顺序产生不同的结果。
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
组:副作用 |
类别:必需 |
AGC 类别:必需 |
版本历史记录
在 R2014b 中推出另请参阅
MISRA C:2012 Dir 4.9
| MISRA C:2012 Rule 13.1
| MISRA C:2012 Rule 13.3
| MISRA C:2012 Rule 13.4
| 检查 MISRA C:2012 (-misra3)
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.