Crafting Better Source Code in C++
Eljay Love-Jensen
eljay@adobe.com
Sun Mar 21 19:50:00 GMT 2004
Hi everyone,
#define SOAPBOX
I've been asked this question several times about C++ (in particular, GCC's
C++), and I thought I'd share my thoughts.
The GCC compiler has a suite of warnings which will point out dangerous or
suspicious coding practices. By and large, I feel that these GCC warnings
are indicative of either bad code ("bugs"! ~10% of the time), or poor
coding practices (~90%).
In either case, I think it is a worthwhile endeavor to use GCC's warning
facilities to help improve the source code, and improve the portability of
the source code.
At a minimum, I suggest everyone ALWAYS use these flags:
-pedantic -Wall -W
Other flags are documented here:
http://gcc.gnu.org/onlinedocs/gcc-3.3.3/gcc/Warning-Options.html
I use almost all the additional flags. Call me ultra-pedantic. I wish
there was an -WALL switch, to enable all warnings (even the annoying ones
which I disregard), just so I wouldn't have the creepy feeling I've missed one.
I have heard of people unhappy that there isn't a good GNU Lint++ for C++
code in general. In my opinion, a good chunk of Lint++ facility is built
right into the GCC compiler. If only people would enable it.
Granted... Gimpel's PC-lint / FlexeLint software does an extensive analysis
beyond what GCC has built in. Gimpel's software has a different objective
than GCC.
#undef SOAPBOX
Thanks,
--Eljay
More information about the Gcc-help
mailing list