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.2、16.3、16.4、16.5 或 16.6。
报告中的补充消息
报告文件中的所有消息均以 "MISRA-C switch statements syntax normative restriction" 开头。
初始化器不得用于开关语句中。
switch 语句的子语句必须是复合语句。
所有开关语句应出现在同一级别。
开关语句仅包含开关标签和开关语句,不包含其他代码。
开关语句只能包含开关标签和开关子句,不能包含其他代码。
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
检查信息
| 组:Switch 语句 |
| 类别:必需 |
| AGC 类别:建议 |
版本历史记录
另请参阅
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.