...
Don't rely on implicit int
typing. C99 Section 6.7.2, "Type specifiers" states:
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each
struct
declaration and type name.
Code Block | ||
---|---|---|
| ||
extern foo; |
Most C90 implementations do not issue a diagnostic for the violation of this C99 constraint. Many C99 translators will continue to treat such declaration as implying the type int
.
Compliant Solution
Code Block | ||
---|---|---|
| ||
extern int foo; |
...
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.
The C90 Standard included the requirement:
If the expression that precedes the parenthesized argument list in a function call consists solely of an identifier, and if no declaration is visible for this identifier, the identifier is implicitly declared exactly as if, in the innermost block containing the function call, the declaration
extern int identifier();
appeared.
A C99 implementation will not perform implicit function declarations.
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 return type)
Risk Assessment
Occurrences of an omitted type specifier in existing code is rare, and the consequences are generally minor.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
DCL31-C | low | unlikely | medium | P2 | L3 |
...
Wiki Markup |
---|
\[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\] \[[Jones 08|AA. C References#Jones 08]\] \[[MISRA 04|AA. C References#MISRA 04]\] Section 6.7.2, "Type specifiers", Section 6.5.2.2, "Function calls" |
...
02. Declarations and Initialization (DCL) DCL32-C. Guarantee that mutually-visible identifiers are unique