Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't -Wstrict-prototypes on by default?

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?

like image 629
Blacklight Shining Avatar asked Apr 16 '15 01:04

Blacklight Shining


Video Answer


2 Answers

-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.

like image 64
DevSolar Avatar answered Nov 12 '22 14:11

DevSolar


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.

like image 23
Peter - Reinstate Monica Avatar answered Nov 12 '22 14:11

Peter - Reinstate Monica