jake jake - 1 year ago 57
C Question

void function parameter in both the definition and declaration? Or just one?

There are a ton of posts explaining why explicitly doing

foo(void)
is better than
foo()
because it specifies that there are no function arguments instead of an unknown amount.

However, I cannot seem to find if it's best practice to put void in both the header file declaration and the source file definition such as:

foo.h

void foo(void);


foo.c

void foo(void)
{
return;
}





OR




foo.h

void foo(void);


foo.c

void foo()
{
return;
}


Which one is better practice, and is there a specific reason to do one over the other?

Answer Source

Old-style function declarations and definitions with empty parentheses are an obsolescent feature (N1570 6.11.6, 6.11.7). There are hardly any good reasons to use them.

Use (void) consistently, not ().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download