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条回答
Emotional °昔
2楼-- · 2019-01-04 16:21

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
查看更多
地球回转人心会变
3楼-- · 2019-01-04 16:23

I usually compile with "-W -Wall -ansi -pedantic" this helps ensure maximum quality and portability of the code.

查看更多
萌系小妹纸
4楼-- · 2019-01-04 16:23

-pedantic-errors

查看更多
神经病院院长
5楼-- · 2019-01-04 16:23

Right now I use:

-Wall -W -Wextra -Wconversion -Wshadow -Wcast-qual -Wwrite-strings -Werror

I took that list mostly from the book "An introduction to gcc" and then some from Ulrich Drepper recomendation about Defensive Programming (http://people.redhat.com/drepper/Defensive-slides.pdf).

But I don't have any science behind my list, it just felt like a good list.

/Johan


Note: I don't like those pedantic flags though....

Note: I think that -W and -Wextra are more or less the same thing.

查看更多
在下西门庆
6楼-- · 2019-01-04 16:25

-Wfatal-errors

查看更多
相关推荐>>
7楼-- · 2019-01-04 16:27

I like -Werror. Keeps the code warning free.

查看更多
登录 后发表回答