Recommended gcc warning options for C [closed]

2019-01-04 15:38发布

Other than -Wall what other warnings have people found useful?

http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Warning-Options.html

15条回答
Animai°情兽
2楼-- · 2019-01-04 16:27

-Wfloat-equal, -Wshadow, -Wmissing-prototypes,

查看更多
霸刀☆藐视天下
3楼-- · 2019-01-04 16:27

-Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wextra -Werror-implicit-function-declaration -Wunused -Wno-unused-value -Wreturn-type

查看更多
趁早两清
4楼-- · 2019-01-04 16:28

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
查看更多
登录 后发表回答