...
This noncompliant 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 declarations as implying the type int
.
...
This compliant solution explicitly includes a type specifier.
Code Block | ||||
---|---|---|---|---|
| ||||
extern int foo; |
Noncompliant Code Example (Implicit Function Declaration)
...
However, to conform with C99, 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; } |
...
Similarly, do not 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
.
Code Block | ||||
---|---|---|---|---|
| ||||
foo(void) { return UINT_MAX; } int main(void) { long long c = foo(); printf("%lld\n", c); return 0; } |
...
This compliant solution explicily 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; } |
...