https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87656

--- Comment #10 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Segher Boessenkool from comment #9)
> (In reply to Eric Gallager from comment #8)
> > Any reason not to put -Wnested-externs in -Wall or -Wextra?
> 
> It warns for any "extern" declaration in other than file scope.  This is
> completely standard C, and useful as well.
> 
> It is harmful to warn about idiomatic code, especially if there is no real
> alternative.
> 
> I don't think anyone will accidentally do this either (you don't type
> "extern" if you don't mean it, after all).
> 
> Do you have any example where this warning helped you find a bug?

It may have been idiomatic 30 years ago, but it isn't any longer. And there's
an easy alternative: just move the declaration out of the function and up to
file scope. It makes more sense that way and looks better. Or, better yet,
include the proper header file for the extern declaration. Most instances I've
seen of the warning have been stuff like people putting "extern int errno"
inside of a function instead of realizing that they're supposed to just do
#include <errno.h> instead (possibly because the code is from before the header
was standardized?). In the errno case it's particularly harmful because errno
may be defined as a macro that's incompatible with the declaration being used.

Reply via email to