为什么默认情况下不启用 -Wstrict-prototypes?
Why isn't -Wstrict-prototypes on by default?
我了解到用空白参数列表定义函数与用 void
作为参数列表定义函数不同。参见(Is it better to use C void arguments "void foo(void)" or not "void foo()"?)。
这种误解对我来说似乎很常见,令我惊讶的是 gcc
和 clang
都没有发出任何警告,即使我通过了 -Wall -Wextra -pedantic
。
这是为什么?
其中一个原因可能是 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.
在 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.
此外,在文档 (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.
选项本身是这样记录的:
`-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.)
选项分开的原因很容易理解,考虑到上下文:这是在 C 标准化后仅几年,很少有程序转换为 ANSI C。gcc 有其他选项可以帮助这,例如 -Wtraditional
.
复杂工具的开发人员必须牢记兼容性。在类别之间移动选项肯定会破坏某些人的构建脚本。例如,gcc 也有
`-Werror'
Make all warnings into errors.
一些人经常使用。不必要地打开开发人员早先选择不使用的警告并因此停止编译并不是保持兼容性的方法。
有关 -Wall
与 -Wstrict-prototypes
的更多上下文,阅读 整个 部分而不是选择性地挑选文本会有所帮助。例如,-Wall
的 current 文档的最后一段指出 -Wall
并不全面,最终包含的原因是一个判断问题(如原始文档中所示):
Note that some warning flags are not implied by -Wall. Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning. Some of them are enabled by -Wextra but many of them must be enabled individually.
至于谁的判断-应该是1990年左右gcc的原始开发者。
那里有很多遗留代码(在 void 之前)会引发误导性警告。随着时间的推移,新代码与旧代码的比例发生变化,因此这些警告变得更加有用。
-Wall
其实只是开始,-Wextra
远不是路的尽头。
我宁愿引用 [=15] 而不是引用 Stallman 先生的话,也不必为了避免评论他的一些更值得怀疑的观点(比如 Thomas Dickey 提到的观点)而不得不咬住我的舌头=],强调我的:
-Wall
-- This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros.
-Wextra
-- This enables some extra warning flags that are not enabled by -Wall.
因此,如果您说“全部,加上额外”,您实际上是在说“简单的,加上一些”。最好查看该手册了解更多信息。
因为非常多的程序员使用空参数列表来表示没有参数,并且所有这些程序员都会被阻止使用包含它的警告集。在翻译 from/to C to/from 另一种编程语言时,使用 (void) 也会导致问题。
我了解到用空白参数列表定义函数与用 void
作为参数列表定义函数不同。参见(Is it better to use C void arguments "void foo(void)" or not "void foo()"?)。
这种误解对我来说似乎很常见,令我惊讶的是 gcc
和 clang
都没有发出任何警告,即使我通过了 -Wall -Wextra -pedantic
。
这是为什么?
其中一个原因可能是 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.
在 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.
此外,在文档 (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.
选项本身是这样记录的:
`-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.)
选项分开的原因很容易理解,考虑到上下文:这是在 C 标准化后仅几年,很少有程序转换为 ANSI C。gcc 有其他选项可以帮助这,例如 -Wtraditional
.
复杂工具的开发人员必须牢记兼容性。在类别之间移动选项肯定会破坏某些人的构建脚本。例如,gcc 也有
`-Werror'
Make all warnings into errors.
一些人经常使用。不必要地打开开发人员早先选择不使用的警告并因此停止编译并不是保持兼容性的方法。
有关 -Wall
与 -Wstrict-prototypes
的更多上下文,阅读 整个 部分而不是选择性地挑选文本会有所帮助。例如,-Wall
的 current 文档的最后一段指出 -Wall
并不全面,最终包含的原因是一个判断问题(如原始文档中所示):
Note that some warning flags are not implied by -Wall. Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning. Some of them are enabled by -Wextra but many of them must be enabled individually.
至于谁的判断-应该是1990年左右gcc的原始开发者。
那里有很多遗留代码(在 void 之前)会引发误导性警告。随着时间的推移,新代码与旧代码的比例发生变化,因此这些警告变得更加有用。
-Wall
其实只是开始,-Wextra
远不是路的尽头。
我宁愿引用 [=15] 而不是引用 Stallman 先生的话,也不必为了避免评论他的一些更值得怀疑的观点(比如 Thomas Dickey 提到的观点)而不得不咬住我的舌头=],强调我的:
-Wall
-- This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros.
-Wextra
-- This enables some extra warning flags that are not enabled by -Wall.
因此,如果您说“全部,加上额外”,您实际上是在说“简单的,加上一些”。最好查看该手册了解更多信息。
因为非常多的程序员使用空参数列表来表示没有参数,并且所有这些程序员都会被阻止使用包含它的警告集。在翻译 from/to C to/from 另一种编程语言时,使用 (void) 也会导致问题。