Why is this an issue?
There is a real, functional difference between a function with an empty parameter list and one with an explicitly void
parameter list:
It is possible to pass parameters to a function with an empty list; the compiler won’t complain. That is not the case for a function with a
void
list. Thus, it is possible, and even easy to invoke empty-list functions incorrectly without knowing it, and thereby introduce the
kind of subtle bug that can be very difficult to track down.
Noncompliant code example
void myfunc (); // Noncompliant
//...
void otherFunc() {
int a = 4;
//...
myfunc(a); // Compiler allows this
}
Compliant solution
void myfunc ( void );
//...
void otherFunc() {
int a = 4;
//...
myfunc(a); // Compiler error!
}
Resources
- MISRA C:2004, 16.5 - Functions with no parameters shall be declared with parameter type void
- CERT, DCL20-C. - Explicitly specify void when a function accepts no arguments