MISRA C:2012 Rule 14.4
The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type
描述
规则定义
The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type 1
理由
强定型要求 if
语句或迭代语句的控制表达式本质上应为布尔类型。
Polyspace 实现
Polyspace® 不会标记整数常量,例如 if(2)
。
分析会识别布尔类型,bool
或 _Bool
(在 stdbool.h
中定义)
您还可以使用有效布尔类型 (-boolean-types)
选项定义本质上为布尔的类型。
故障排除
如果您预计存在违规,但未看到该违规,请参阅Diagnose Why Coding Standard Violations Do Not Appear as Expected。
示例
检查信息
组:控制语句表达式 |
类别:必需 |
AGC 类别:建议 |
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.