You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Because there was a legacy of using functions without declaring them.

Can't use functions without including the headers.

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 to support existing programs that exploited
this feature.

Non-Compliant Code Example (implicit int)

Don't rely on implicit int typing.

extern foo;

Compliant Solution

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.


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)

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

[[ISO/IEC 9899-1999]]
[[MISRA 04]]


      02. Declarations and Initialization (DCL)       DCL32-C. Guarantee that mutually-visible identifiers are unique

  • No labels