Is f(void) deprecated in modern C and C++?
c, c++, refactoring, void
Solution
In C, the declaration `int f(void)` means a function returning int that takes no parameters. The declaration `int f()` means a function returning int that takes any number of parameters. Thus, if you have a function that takes no parameters in C, the former is the correct prototype.
In C++, I believe `int f(void)` is deprecated, and `int f()` is preferred, as it specifically means a function that takes no parameters.
Problem
I'm currently refactoring/tidying up some old C code used in a C++ project, and regularly see functions such as: ``` int f(void) ``` which I would tend to write as: ``` int f() ``` Is there any reason not to replace (void) with () throughout the codebase in order to improve consistency, or is there a subtle difference between the two that I am unaware of? More specifically, if a virtual member function in C++ is described as: ``` virtual int f(void) ``` and a derived class includes a member function: ``` int f() ``` is this a valid override? Additionally, am I likely to encounter any linker problems based on almost identical signatures?
Related problems
- Understanding the difference between f() and f(void) in C and C++ once and for all
- Is it better to use C void arguments "void foo(void)" or not "void foo()"?
- Is there a difference between foo(void) and foo() in C++ or C?
- Why add void to method parameter list
- Understanding the difference between f() and f(void) in C and C++ once and for all
- Is there a difference between foo(void) and foo() in C++ or C?