Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

warnings - gcc : Is using -Werror and -pedantic considered good practice?

I'm just digging into the gcc manual and some things are still unclear to me:

  1. When specifying a std, should I always use -pedantic in conjunction?
  2. When using -g, it the standard level sufficient or should I specify level 3, i.e. -g3?
  3. Is it good practice to use -Werror to promote all warnings to errors and -pedantic-errors to promote all pedantic warnings to errors?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are writing a library, please do make sure that a simple program like

#include <yourlib.h>
int main() {
    return 0;
}

compiles without any warnings whatsoever even when the compiler is running in the most pedantic mode with all optional warnings enabled.

If you are writing an application, your code throwing warnings left and right is just your application's problem. With a library's public header file, however, everybody who later uses that library will be forced to ignore or endure the warnings your header file is causing.

So please check that your library headers compile without warnings, if possible in multiple compiler modes:

$ gcc -Wall -Wextra -Werror -std=c99   -pedantic
$ gcc -Wall -Wextra -Werror -std=gnu99 -pedantic
$ gcc -Wall -Wextra -Werror -std=c89   -pedantic
$ gcc -Wall -Wextra -Werror -std=gnu89 -pedantic

How many warnings compiling your library throws is again only your problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...