MISRA C:2023 Rule 8.1
描述
规则定义
Types shall be explicitly specified 1 .
理由
在一些情况下,您可以省略 C90 标准中的类型。在这些情况下,会隐式指定 int
类型。然而,省略显式类型可能会让人感到困惑。例如,在声明 extern void foo (char c, const k);
中,k
的类型是 const int
,但您期望的可能是 const char
。
您可以在以下声明中使用隐式类型:
对象声明
参数声明
成员声明
typedef
声明函数返回类型
Polyspace 实现
规则检查项会标记未显式指定函数参数或返回类型的情况。
故障排除
如果您预计存在违规,但未看到该违规,请参阅Diagnose Why Coding Standard Violations Do Not Appear as Expected。
示例
检查信息
组:声明和定义 |
类别:必需 |
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.