
difference between void foo(void) and void foo()
Quote:
> What is the difference between
> void foo(void) {...} - foo is a function with no parameters returning
> void
> and
> void foo() {...} - foo is a function with no parameter specification
> returning void
In a function definition, nothing. Either is declared to take no
parameters. If you call them with parameters, that is, IIRC, a
constraint violation.
If these were declarations, but _not_ definitions (i.e., if the {...}
were replaced by a ;), the second would not be declared to take any
parameters. You could define it elsewhere to take parameters and call it
with parameters; there is no way for the compiler to tell from this
declaration alone how many it takes. Note that calling such a function
with the wrong number of parameters is undefined behaviour, i.e., if you
do, truly anything may happen.
If the first were a declaration, but not a definition, nothing would
change in the number of parameters.
Note that, while the second is not illegal, it is rather bad practice.
Prototypes were made to be used for your security and clarification; use
them.
Richard