11th: watch your compiler warnings
Sat, 03 Jan 2015 18:13:47 +0000
Few, most important in my opinion, however mostly overlooked GCC compiler switches:
- -Wall: enables all the warnings about constructions that some users consider questionable, very likely a programming mistakes
- -Wextra: enables some extra warning flags that are not enabled by -Wall
- -Winit-self: warn about uninitialized variables which are initialized with themselves
- -Wold-style-cast: warn if an old-style (C-style) cast to a non-void type is used within a C++ program
- -Woverloaded-virtual: warn when a function declaration hides virtual functions from a base class
- -Wuninitialized: warn if an automatic variable is used without first being initialized
- -Wmissing-declarations: warn if a global function is defined without a previous declaration
- -ansi, -std=standard: specify the C/C++ standard level used
- -pedantic: issue all the warnings demanded by strict ISO C and ISO C++, and -pedantic-errors that tunrs them into errors (aborts compilation)
and the most important one:
- -Werror: turns warnings into errors, so your build would go red in case of any warning
I must admit we used to use "-Werror" extensively for many years and many pitfalls are omitted then automatically.