Declaring a Function with No Parameters
suggest changeFor code that must compile as C17 or earlier, use void to declare that a function accepts no arguments:
int answer(void);
int answer(void)
{
return 42;
}
In those language versions, int answer(); declares a function with an unspecified parameter list. It does not provide a prototype, so the declaration cannot diagnose all incorrect calls. An empty parameter list in a function definition is an old-style definition and should also be avoided.
C23 changed this rule: an empty parameter list means that the function has no parameters, so int answer(); is a prototype in C23. Spelling (void) remains clear and preserves compatibility with older C modes.
The same guidance applies to main when command-line arguments are not needed:
int main(void)
{
return 0;
}
Enable warnings for declarations without prototypes when maintaining code compiled in C17 or earlier. Do not rely on a permissive compiler accepting calls whose arguments do not match a visible prototype.