隐式函数声明¶
ID: cpp/implicit-function-declaration
Kind: problem
Security severity:
Severity: warning
Precision: high
Tags:
- correctness
- maintainability
Query suites:
- cpp-security-and-quality.qls
在没有先前的函数声明或定义的情况下调用函数。发生这种情况时,编译器会生成函数的隐式声明,指定整数返回值类型和无参数。如果隐式声明与函数的真实签名不匹配,则函数的行为可能不可预测。
这可能表明函数名称拼写错误,或者包含函数声明的必需头文件未包含在内。
建议¶
在调用函数之前提供该函数的显式声明。
示例¶
/* '#include <stdlib.h>' was forgotten */
int main(void) {
/* 'int malloc()' assumed */
unsigned char *p = malloc(100);
*p = 'a';
return 0;
}
参考¶
SEI CERT C 编码标准:DCL31-C. Declare identifiers before using them