且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MinGW的编译器不需要函数声明?

更新时间:2022-04-12 09:52:18

这是C,它不应该被以前作为几十年遗留下来的功能。您应该使用编译器的设置,如果你做这样的事情,我们会警告你。 GCC有几个开关使用时,与放大器,您应该指定;其中一人会给你一个警告这一点。

This is a legacy "feature" of C that should not be used as of several decades ago. You should use a compiler with settings that will warn you if you do something like this. Gcc has several switches that you should specify when using it & one of them will give you a warning for this.

编辑:我没有被使用gcc自己,但你应该检查开关-pedantic,-Wall,-Wextra和-std

I haven't been using gcc myself, but switches that you should check out are -pedantic, -Wall, -Wextra, and -std.

这是接受这是假设,每个旧的语言定义,因为你没有看到适合否则告诉它的编译器,函数)返回一个int值和b)因为你传递一个int(或如果你通过它的东西,可以被提升到一个int)函数期望参数是一个int。

The compiler that is accepting this is assuming, per the old language definition, that since you didn't see fit to tell it otherwise, the function a) returns an int value and b) since you pass it an int (or if you passed it something that could be promoted to an int) the function expects that argument to be an int.

由于@veer正确地指出,这应该一般工作在你的具体情况。在其他情况下,但是,对于一个函数没有原型的隐含假设和函数的实际签名之间的差异会使得事情热潮。

As @veer correctly points out, this should generally work in your particular case. In other cases, however, differences between the implicit assumptions for a function without a prototype and the function's actual signature would make things go boom.