MISRA C:2012 Rule 16.1
All switch statements shall be well-formed
描述
All switch statements shall be well-formed 1
理由
C 语言中 switch 语句的语法并不十分严格,可能会导致复杂、非结构化的行为。这条规则和其他相关规则一起,要求 switch 语句采用简单且一致的结构体。
Polyspace 实现
按照 MISRA™ 规范,如果 switch 语句违反了以下某条规则,编码规则检查项也会报告违反了规则 16.1:16.2、16.3、16.4、16.5 或 16.6。
报告中的补充消息
All messages in report file begin with "MISRA-C switch statements syntax normative restriction."
Initializers shall not be used in switch clauses.
The child statement of a switch shall be a compound statement.
All switch clauses shall appear at the same level.
A switch clause shall only contain switch labels and switch clauses, and no other code.
A switch statement shall only contain switch labels and switch clauses, and no other code.
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
检查信息
| 组:Switch 语句 |
| 类别:必需 |
| AGC 类别:建议 |
PQL 名称:std.misra_c_2012.R16_1 |
版本历史记录
另请参阅
MISRA C:2012 Rule 15.3 | MISRA C:2012 Rule 16.2 | MISRA C:2012 Rule 16.3 | MISRA C:2012 Rule 16.4 | MISRA C:2012 Rule 16.5 | MISRA C:2012 Rule 16.6 | 检查 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.