...
This noncompliant code example omits the type specifier.:
Code Block | ||||
---|---|---|---|---|
| ||||
extern foo; |
...
This compliant solution explicitly includes a type specifier.:
Code Block | ||||
---|---|---|---|---|
| ||||
extern int foo; |
...
However, to conform with the C Standard, you must explicitly prototype every function before invoking it. This noncompliant example fails to prototype the foo()
function before invoking it in main()
.:
Code Block | ||||
---|---|---|---|---|
| ||||
int main(void) { int c = foo(); printf("%d\n", c); return 0; } int foo(int a) { return a; } |
...
In this compliant solution, a prototype for foo()
appears before the function invocation.:
Code Block | ||||
---|---|---|---|---|
| ||||
int foo(int); int main(void) { int c = foo(0); printf("%d\n", c); return 0; } int foo(int a) { return a; } |
...
This compliant solution explicitly defines the return type of foo()
as unsigned int
.:
Code Block | ||||
---|---|---|---|---|
| ||||
unsigned int foo(void) { return UINT_MAX; } int main(void) { long long c = foo(); printf("%lld\n", c); return 0; } |
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Compass/ROSE |
|
|
| ||||||
| decltype | Fully implemented. | |||||||
GCC |
|
| Can detect violations of this rule when the | ||||||
| IF_MISS_DECL RETVOID.IMPLICIT |
| |||||||
| 24 D | Fully implemented. | |||||||
PRQA QA-C |
| 0434 (C) | Fully implemented. |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...
ISO/IEC TR 24772:2013 | Subprogram Signature Mismatch [OTR] |
MISRA - C:2012 |
Bibliography
[ISO/IEC 9899:2011] | Section 6.7.2, "Type Specifiers" |
[Jones 2008] |
...