I have the following C/C++ program, and I compile it with all warnings on.
int foo(int x) { return 5; }
The C++ compiler gives me a warning about unreferenced formal parameter. When I remove “x” so that the signature reads “int foo(int)”, the compiler is happy.
The C compiler, on the other hand, likes the named parameter and issues warning when it is unnamed.
EDIT: It issues an error, not warning.
Why the difference? What’s the rationale?
P.S. I’m using the GNU compiler toolchain.
One reason for C might be that it still has the old-style parameter list that only consist of identifiers:
So basically when it only sees an identifier, it has to assume that this is a variable name and not a type.