Skip to main content
1 of 2
ljrk
  • 919
  • 5
  • 11

Most people don't know that these function declarations

int foo();
int bar() { }

do not declare a prototype for foo respectively bar. In consequence, this is a legal implementation of foo:

int foo(int a) { }

And this is a likely illegal call to bar, however the compiler can't warn:

bar(42);

To provide a prototype, add void inside the parenthesis to make it a parameter-list (instead of the C89 identifier list) and all of the above would yield compile time errors:

int foo(void);
int bar(void) {}

This is due to Cs history of K&R style function declarations and definitions:

int foo();

int foo(a)
int a;
{
   /* do something */
}

Compatibility is great, but I don't think you should go lower than C99 if not explicitly needed.

ljrk
  • 919
  • 5
  • 11