...
A new feature of C99: The rule for implicit declaration of functions has been removed in C99.
The effect is to guarantee the production of a diagnostic that will catch an additional category of
25 programming errors. After issuing the diagnostic, an implementation may choose to assume an
implicit declaration and continue translation in order to support existing programs that exploited
this feature.
Non-Compliant Code Example (implicit int)
Don't rely on implicit int
typing.
Code Block | ||
---|---|---|
| ||
extern foo;
|
Compliant Solution
Code Block | ||
---|---|---|
| ||
extern int foo;
|
Non-Compliant Code Example (implicit function declaration)
Implicit declaration of functions is not allowed: every function must be explicitly declared before it can be called. In C89, if a function is called without an explicit prototype, the compiler provides an implicit declaration.
Code Block | ||
---|---|---|
| ||
If a function declaration is not visible at the point at which a call to the function is made, some compilers assume an implicit declaration of extern int func()
; However, for conformance to C99, you should explicitly prototype every function before making a call to it.
Compliant Solution (implicit function declaration)
Code Block | ||
---|---|---|
| ||
extern int foo;
|
Non-Compliant Code Example (implicit return type)
Similarly, don't declare a function with implicit return type. If it returns a meaningful integer value, declare it int. If it returns no meaningful value, declare it void.
Compliant Solution (implicit return type)
Risk Assessment
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
DCL31-C | low | unlikely | medium | P2 | L3 |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
Wiki Markup |
---|
\[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\]
\[[MISRA 04|AA. C References#MISRA 04]\] |
...
02. Declarations and Initialization (DCL) DCL32-C. Guarantee that mutually-visible identifiers are unique