Recommended gcc warning options for C [closed]
I routinely use:
gcc -m64 -std=c99 -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-qual \ -Wstrict-prototypes -Wmissing-prototypes
This set catches a lot for people unused to it (people whose code I get to compile with those flags for the first time); it seldom gives me a problem (though -Wcast-qual is occasionally a nuisance).
As of 2011-09-01, with gcc version 4.6.1
My current "development" alias
gcc -std=c89 -pedantic -Wall \ -Wno-missing-braces -Wextra -Wno-missing-field-initializers -Wformat=2 \ -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith \ -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline \ -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code \ -Wlogical-op -Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls \ -Wold-style-definition -Werror \ -ggdb3 \ -O0 \ -fno-omit-frame-pointer -ffloat-store -fno-common -fstrict-aliasing \ -lm
The "release" alias
gcc -std=c89 -pedantic -O3 -DNDEBUG -flto -lm
As of 2009-11-03
"development" alias
gcc -Wall -Wextra -Wformat=2 -Wswitch-default -Wcast-align -Wpointer-arith \ -Wbad-function-cast -Wstrict-prototypes -Winline -Wundef -Wnested-externs \ -Wcast-qual -Wshadow -Wwrite-strings -Wconversion -Wunreachable-code \ -Wstrict-aliasing=2 -ffloat-store -fno-common -fstrict-aliasing \ -lm -std=c89 -pedantic -O0 -ggdb3 -pg --coverage
"release" alias
gcc -lm -std=c89 -pedantic -O3 -DNDEBUG --combine -fwhole-program -funroll-loops
I started out with C++, so when I made the switch to learning C I made sure to be extra-anal:
-fmessage-length=0-ansi -pedantic -std=c99-Werror-Wall-Wextra-Wwrite-strings-Winit-self-Wcast-align-Wcast-qual-Wpointer-arith-Wstrict-aliasing-Wformat=2-Wmissing-declarations-Wmissing-include-dirs-Wno-unused-parameter-Wuninitialized-Wold-style-definition-Wstrict-prototypes-Wmissing-prototypes