Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Implicit declaration of functions is not allowed: every function should 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 Standard [ISO/IEC 9899:1990] includes this requirement:

...

In the following noncompliant code example, if malloc() is not declared, either explicitly or by including stdlib.h, a compiler may implicitly declare malloc() as int malloc(). (Compilers that comply only with C90 are required to provide an implicit declaration of malloc().) If the platform's size of int is 32 bits, but the size of pointers is 64 bits, the resulting pointer could be truncated as a result of the implicit declaration of malloc() returning a 32-bit integer.

 

Code Block
bgColor#ffcccc
langc
/* #include <stdlib.h> is missing */
 
int main(void) {
  size_t i;
  for (i = 0; i < 100; ++i) {
    char *ptr = (char*)malloc(0x10000000); /* int malloc() assumed */
    *ptr = 'a';
  }
  return 0;
}

When compiled with Microsoft Visual Studio (a C90-only platform), the preceding code will eventually cause an access violation when dereferencing ptr in the loop.

...

ISO/IEC TR 24772:2013Subprogram Signature Mismatch [OTR]
MISRA C:2012 

Bibliography

[ISO/IEC 9899:1990] 
[ISO/IEC 9899:2011]Subclause 6.7.2, "Type Specifiers"
[Jones 2008] 

...