☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

switch 语句不应只包含一个 case 标签

9.5.10 ID_switch_onlyOneCase
目录 › next › previous

只有一个 case 标签的 switch 语句与 if 语句语义相同,但形式上更为复杂,应改为 if 语句。

示例:

switch (v)
{
case 123:    // Non-compliant
    ....
    break;
}

应改为:

if (v == 123)
{
    ....
}

参考

MISRA C 2012 16.6
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.