Always use -O
or above (-O1
, -O2
, -Os
, etc.). At the default optimization level, gcc goes for compilation speed and doesn't do enough analysis to warn about things like unitialized variables.
Consider making -Werror
policy, as warnings that don't stop the compilation tend to be ignored.
-Wall
pretty much turns on the warnings that are very likely to be errors.
Warnings included in -Wextra
tend to flag common, legitimate code. They may be useful for code reviews (though lint-style programs find a lot more pitfalls are more flexible), but I wouldn't turn them on for normal development.
-Wfloat-equal
is a good idea if the developers on the project are unfamiliar with floating point, and a bad idea if they are.
-Winit-self
is useful; I wonder why it's not included in -Wuninitialized
.
-Wpointer-arith
is useful if you have mostly-portable code that doesn't work with -pedantic
.
-save-temps
,-Wshadow
and-fmudflap
were the greatest finds I didn't know of, thanks to all. – Matt Joinergcc -c [flags-go-here] -o myprog.o myprog.c
to compile (not link) a C program. – Rory O'Kane