Monday, October 11, 2010

When it comes to GCC warnings, all does not mean all

The GNU Compiler Collection, or GCC, is a stable and mature C/C++ compiler, with perhaps the most extensive set of command-line options ever provided on any program ever written.

Lately, I've been studying the options for generating warnings, as I've been trying to learn more about my code by getting the compiler to tell me things that it notices.

At first, I thought, it seems simple enough: just specify -Wall, which ought to mean "turn on ALL the warnings."



All of the above `-W' options combined. 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. This also enables some language-specific warnings described in C++ Dialect Options and Objective-C and Objective-C++ Dialect Options.

And then, you get to:

The following -W... options are not implied by -Wall. Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning.

And it's a long list; I counted about 50 warnings in the list of available-warnings-which-aren't-implied-by-Wall.

So, the bottom line is: if you're using GCC, and you're trying to investigate compiler warnings, and you think that -Wall is giving you the warnings that you should study, well, you're definitely not seeing all the warnings and you may not even be seeing the most interesting warnings!

It's worth spending time reading through all the warnings and looking for ones that match your organization's style and coding techniques, and picking out as many as you can to enable. Let your compiler help you!

No comments:

Post a Comment