Is it better to use C void arguments "void foo(void)" or not "void foo()"?
c, void
Solution
void foo(void);
That is the correct way to say "no parameters" in C, and it also works in C++.
But:
void foo();
Means different things in C and C++! In C it means "could take any number of parameters of unknown types", and in C++ it means the same as `foo(void)`.
Variable argument list functions are inherently un-typesafe and should be avoided where possible.
Problem
What is better: `void foo()` or `void foo(void)`? With void it looks ugly and inconsistent, but I've been told that it is good. Is this true? Edit: I know some old compilers do weird things, but if I'm using just GCC, is `void foo()` Ok? Will `foo(bar);` then be accepted?
Related problems
- Why does gcc allow arguments to be passed to a function defined to be with no arguments?
- Is there a difference between foo(void) and foo() in C++ or C?
- Why does an empty declaration work for definitions with int arguments but not for float arguments?
- func() vs func(void) in C99
- Is there a difference between foo(void) and foo() in C++ or C?