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

后端 未结 4 1924
执念已碎
执念已碎 2020-12-15 19:55

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. Wh
4条回答
  •  一整个雨季
    2020-12-15 20:52

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

    #include 
    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.

提交回复
热议问题