The previous C90 standard of C90 allowed allows for implicit typing of variables and functions. Because implicit declarations lead to less stringent type checking, they can often introduce unexpected and erroneous behavior or even security vulnerabilities.
Two new features of C99 are to require The C99 standard requires type identifiers and to forbid forbids implicit function declarations. After issuing the diagnostic, an implementation may choose to assume an implicit declaration and continue translation to support existing programs that exploited used this feature.
Non-Compliant Code Example (implicit int)
C90 Section 6.5.2 allowed allows for the absence of type specifiers in a declaration. In which casethese cases, the type was is defined to be that of a signed int
.
Don't Do not 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.
This non-compliant code example omits the type specifier.
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 declarations as implying the type int
.
Compliant Solution
...
Code Block | ||
---|---|---|
| ||
int main(void) { int c = foo(); printf("%d\n", c); return 0; } int foo(int a) { return a; } |
Because the compiler assumes foo()
to have type extern int foo()
, it cannot spot diagnose the missing argument and a bogus value is printed.
...
Code Block | ||
---|---|---|
| ||
int foo(int); int main(void) { int c = foo(0); printf("%d\n", c); return 0; } int foo(int a) { return a; } |
...