为什么默认情况下不启用-Wstrict-prototypes?

Bla*_*ing 7 gcc clang compiler-warnings

我了解到,使用空白参数列表定义函数与使用参数列表定义函数不同void.请参阅(使用C void参数"void foo(void)"或"void foo()"是否更好?).

这种误解似乎对我来说是一个常见的错误,我很惊讶,即使我通过,也gcc没有clang发出任何警告-Wall -Wextra -pedantic.

为什么是这样?

Dev*_*lar 12

-Wall实际上只是开始,而-Wextra不是到目前为止的结束.

而不是引用Stallman先生,并且不得不大肆削减我的舌头以避免评论他的一些更有问题的意见(如Thomas Dickey提到的那些),我宁愿引用当前的GCC手册,强调我的:

-Wall- 这将启用有关某些用户认为有问题且易于避免(或修改以防止警告)的构造的所有警告,即使与宏结合使用也是如此.

-Wextra- 这会启用一些未被-Wall启用的额外警告标志.

所以,如果你说"all,plus extra",你实际上是在说"容易的,加上一些".更好地检查手册.

  • @BlacklightShining:这里的消息是,a)*总是以最严格的错误检查模式运行编译器*,而b)`-Wall -Wextra`不是它.;-) (3认同)

Tho*_*key 8

原因之一可能是 gcc 的创建者和最初的首席开发人员 Richard Stallman 的个人品味。这是我上面提到的他的消息:

Date: Thu, 2 Sep 1999 23:19:27 -0400
Message-Id: <gnusenet199909030319.XAA08701@psilocin.gnu.org>
From: Richard Stallman <rms@gnu.org>
To: gnu-prog@gnu.org
Subject: On using -Wall in GCC
Reply-to: rms@gnu.org
Resent-From: info-gnu-prog-request@gnu.org

Status: RO
Content-Length: 841
Lines: 17

I'd like to remind all GNU developers that the GNU Project
does not urge or recommend using the GCC -Wall option.

When I implemented the -Wall option, I implemented every warning that
anyone asked for (if it was possible).  I implemented warnings that
seemed useful, and warnings that seemed silly, deliberately without
judging them, to produce a feature which is at the upper limit of 
strictness.

If you want such strict criteria for your programs, then -Wall is for
you.  But changing code to avoid them is a lot of work.  If you don't
feel inclined to do that work, please don't let anyone else pressure
you into using -Wall.  If people say they would like to use it, you
don't have to listen.  They're asking you to do a lot of work.
If you don't feel it is useful, you don't have to do it.

I never use -Wall myself.
Run Code Online (Sandbox Code Playgroud)

在gcc-2.7.2.3的ChangeLog.4文件中,该-Wstrict-prototypes选项(尽管在 1992 年 1 月的 gcc 1.42 中出现过)首次被提及为与 不同-Wall:

Thu Nov 21 15:34:27 1991  Michael Meissner  (meissner at osf.org)

        * gcc.texinfo (warning options): Make the documentation agree with
        the code, -Wstrict-prototypes and -Wmissing-prototypes are not
        turned on via -Wall; -Wnoparenthesis is now spelled
        -Wno-parenthesis.
        (option header): Mention that -W options take the no- prefix as well
        as -f options.
Run Code Online (Sandbox Code Playgroud)

另外,在文档 ( gcc.info-3) 中,它出现在本段开头的部分中:

   The remaining `-W...' options are not implied by `-Wall' because
they warn about constructions that we consider reasonable to use, on
occasion, in clean programs.
Run Code Online (Sandbox Code Playgroud)

该选项本身的记录如下:

`-Wstrict-prototypes'
     Warn if a function is declared or defined without specifying the
     argument types.  (An old-style function definition is permitted
     without a warning if preceded by a declaration which specifies the
     argument types.)
Run Code Online (Sandbox Code Playgroud)

考虑到上下文,该选项分开的原因很容易理解:这只是 C 标准化几年后,很少有程序被转换为 ANSI C。gcc 还有其他选项可以帮助解决这个问题,例如-Wtraditional.

复杂工具的开发人员必须牢记兼容性。在类别之间移动选项肯定会破坏某些人的构建脚本。例如,gcc 也有

`-Werror'
     Make all warnings into errors.
Run Code Online (Sandbox Code Playgroud)

有些人经常使用。不必要地打开开发人员之前选择不使用的警告并因此停止编译并不是维护兼容性的方法。

-Wall要了解更多有关vs的上下文,-Wstrict-prototypes阅读整个部分而不是选择性地挑选文本会有所帮助。例如,当前文档中的最后一段-Wall指出这-Wall并不全面,最终包含的原因是判断问题(如原始文档中所示):

请注意,-Wall 并未暗示某些警告标志。其中一些警告用户通常认为没有问题的结构,但有时您可能希望检查一下;其他人警告在某些情况下必要或难以避免的构造,并且没有简单的方法来修改代码来抑制警告。其中一些由 -Wextra 启用,但其中许多必须单独启用。

至于是谁的判断——应该是 1990 年左右 gcc 的原始开发者。

  • 还有比无知更糟糕的事情(例如,断章取义)。 (2认同)