I learned that defining a function with a blank argument list is not the same as defining a function with void
as the argument list. See ( Is it better to use C void arguments "void foo(void)" or not "void foo()"? ).
This misconception seems like a common one to me and I was surprised that neither gcc
nor clang
issued any warnings, even when I passed -Wall -Wextra -pedantic
.
Why is this?
-Wall
is actually only the beginning, and -Wextra
not the end of the road by far.
Instead of quoting Mr. Stallman, and having to bite down on my tongue heavily to avoid commenting on some of his more questionable opinions (like the one referred to by Thomas Dickey), I'd rather quote the current GCC manuals, emphasis mine:
-Wall
-- This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros.
-Wextra
-- This enables some extra warning flags that are not enabled by -Wall.
So, if you say "all, plus extra", you're actually saying "easy ones, plus some". Better check that manual for more.
There was a lot of legacy code out there (from before void) which would throw misleading warnings. Over time the ratio of new code to old code changes so that these warnings become more useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With