Skip to main content
added 59 characters in body
Source Link
ljrk
  • 919
  • 5
  • 11

Most people don't know that theseAdding to the other answers: 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., especially if it lessens the likelihood of severe bugs ;)

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.

Adding to the other answers: 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, especially if it lessens the likelihood of severe bugs ;)

Source Link
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.