The previous standard of C90 allowed for implicit typing of variables and functions. Since Because implicit declarations lead to less stringent type checking, they can often introduce unexpected and erroneous behavior or even security vulnerabilities.
...
Code Block | ||
---|---|---|
| ||
int main(void) { int c = foo(); printf("%d\n", c); return 0; } int foo(int a) { return a; } |
Since Because the compiler assumes foo()
to have type extern int foo()
, it cannot spot 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; } |
For more information on function declarations see \[[DCL07-A. Include the appropriate type information in function declarators]\]. Wiki Markup
Non-Compliant Code Example (implicit return type)
...
Code Block | ||
---|---|---|
| ||
foo() { return UINT_MAX; } int main(void) { long long c = foo(); printf("%lld\n", c); return 0; } |
Since Because the compiler assumes that foo()
returns a value of type int
, UINT_MAX
is incorrectly converted to -1.
...