主要内容

MISRA C:2023 Rule 8.2

Function types shall be in prototype form with named parameters

自 R2024a 起

描述

规则定义

Function types shall be in prototype form with named parameters 1 .

理由

此规则要求您在声明中为所有参数指定名称和数据类型。参数名称提供了有关函数接口的有用信息。声明和定义之间的不匹配可能指示存在编程错误。例如,您在定义函数时混淆了参数。通过强制要求使用参数名称,此规则可让代码评审检测到这种不匹配。

Polyspace 实现

如果函数声明或定义中的参数缺少名称或数据类型,规则检查项将显示违规。

故障排除

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

示例

全部展开

extern int func(int);   /* Non compliant */
extern int func2(int n);   /* Compliant */

extern int func3();   /* Non compliant */
extern int func4(void);   /* Compliant */

在此示例中,funcfunc3 的声明不符合规则,因为参数缺失或没有名称。

检查信息

组:声明和定义
类别:必需
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.