主要内容

MISRA C:2023 Rule 16.1

All switch statements shall be well-formed

自 R2024a 起

描述

规则定义

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。

故障排除

如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示

检查信息

组:Switch 语句
类别:必需
AGC 类别:建议

版本历史记录

在 R2024a 中推出


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.