program story

C에 권장되는 gcc 경고 옵션

inputbox 2020. 10. 10. 10:02
반응형

C에 권장되는 gcc 경고 옵션


-Wall 외에 사람들이 유용하다고 생각한 다른 경고는 무엇입니까?

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


나는 일상적으로 다음을 사용합니다.

    gcc -m64 -std=c99 -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-qual \
        -Wstrict-prototypes -Wmissing-prototypes

이 세트는 익숙하지 않은 사람들 (처음으로 해당 플래그로 코드를 컴파일하는 사람들)을 위해 많은 것을 잡습니다. 거의 문제가되지 않습니다 (-Wcast-qual은 때때로 성가신 일임).


2011-09-01 기준, gcc 버전 4.6.1 포함

내 현재 "개발"별칭

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

"release"별칭

gcc -std = c89 -pedantic -O3 -DNDEBUG -flto -lm

2009-11-03 기준

"development"별칭

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-범위

"release"별칭

gcc -lm -std = c89 -pedantic -O3 -DNDEBUG -combine -fwhole-program -funroll-loops

나는 -Werror를 좋아합니다. 코드 경고를 무료로 유지합니다.


저는 C ++로 시작 했으므로 CI 학습으로 전환했을 때 추가 항문을 사용해야했습니다.

-f 메시지 길이 = 0
-ansi -pedantic -std = c99
-공포
-벽
-Wextra
-Wwrite- 문자열
-Winit-self
-Wcast 정렬
-Wcast-qual
-Wpointer-arith
-Wstrict-aliasing
-Wformat = 2
-Wmissing 선언
-Wmissing-include-dirs
-Wno-unused-parameter
-Wuninitialized
-월드 스타일 정의
-Wstrict 프로토 타입
-Wmissing 프로토 타입

사용하는 GCC 버전에 대한 설명서를 가져와 사용 가능한 모든 경고 옵션을 찾은 다음 설득력있는 이유 가있는 옵션 비활성화하십시오 . (예를 들어, 그렇지 않으면 많은 경고를 제공하는 수정 불가능한 타사 헤더) 이러한 이유를 문서화하십시오. (Makefile에서 또는 해당 옵션을 설정하는 곳마다.) 정기적으로 그리고 컴파일러를 업그레이드 할 때마다 설정을 검토하십시오 .

The compiler is your friend. Warnings are your friend. Give the compiler as much chance to tell you of potential problems as possible.


I also use:

-Wstrict-overflow=5

To catch those nasty bugs that may occur if I write code that relies on the overflow behaviour of integers.

And:

-Wextra

Which enables some options that are nice to have as well. Most are for C++ though.


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


-pedantic -Wall -Wextra -Wno-write-strings -Wno-unused-parameter

For "Hurt me plenty" mode, I leave away the -Wno...

I like to have my code warning free, especially with C++. While C compiler warnings can often be ignored, many C++ warnings show fundamental defects in the source code.


-pedantic-errors


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


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


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.


I generally just use

gcc -Wall -W -Wunused-parameter -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wsign-compare -Wconversion -Wshadow -Wcast-align -Wparentheses -Wsequence-point -Wdeclaration-after-statement -Wundef -Wpointer-arith -Wnested-externs -Wredundant-decls -Werror -Wdisabled-optimization -pedantic -funit-at-a-time -o

The warning about uninitialized variables doesn't work unless you specify -O, so I include that in my list:

-g -O -Wall -Werror -Wextra -pedantic -std=c99

-Wfatal-errors

참고URL : https://stackoverflow.com/questions/154630/recommended-gcc-warning-options-for-c

반응형