gpt4 book ai didi

g++ - 在学习 C++ 时,我应该总是使用带有 g++ 的 -Wall 和 -pedantic 开关吗?

转载 作者:行者123 更新时间:2023-12-01 01:31:49 25 4
gpt4 key购买 nike

作为一个--新手,我想知道在学习 C++ 时总是使用这些标志(使用 g++)是否有益?

谢谢

最佳答案

只要您了解其他人编写的代码示例可能会导致警告 -Wall ,那么是的,这是一个很好的标志,因为它让您养成编写代码的习惯,这些代码没有编译器可能能够识别的任何潜在灰色区域。
-pedantic ,另一方面,是一个棘手的情况。以下是 GCC 4.4.4 联机帮助页对此的说明:

Issue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++. For ISO C, follows the version of the ISO C standard specified by any -std option used.

Valid ISO C and ISO C++ programs should compile properly with or without this option (though a rare few will require -ansi or a -std option specifying the required version of ISO C). However, without this option, certain GNU extensions and traditional C and C++ features are supported as well. With this option, they are rejected.

-pedantic does not cause warning messages for use of the alternate keywords whose names begin and end with __. Pedantic warnings are also disabled in the expression that follows "__extension__". However, only system header files should use these escape routes; application programs should avoid them.

Some users try to use -pedantic to check programs for strict ISO C conformance. They soon find that it does not do quite what they want: it finds some non-ISO practices, but not all---only those for which ISO C requires a diagnostic, and some others for which diagnostics have been added.

A feature to report any failure to conform to ISO C might be useful in some instances, but would require considerable additional work and would be quite different from -pedantic. We don't have plans to support such a feature in the near future.

关于g++ - 在学习 C++ 时,我应该总是使用带有 g++ 的 -Wall 和 -pedantic 开关吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4301425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com