jake jake - 1 month ago 9
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

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 ().