在函数名之后声明函数参数
int func(x)
int x;
{
.............
这种声明叫什么?
何时有效/无效(包括 C 或 C++、某些标准修订版和编译器)?
int func(x)
int x;
{
.............
What is this kind of declaration called?
When is it valid/invalid including C or C++, certain standard revisions and compilers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
即 K&RC 参数声明语法,该语法在 ANSI C 中有效,但在 C++ 中无效。
That is K&R C parameter declaration syntax, which is valid in ANSI C but not in C++.
它仍然有效,但它是 ANSI 之前的版本。 这实际上就是 K&R 缩进样式得名的地方。 左括号位于功能块后面的行上,因为这看起来很奇怪:
无论如何,不推荐这种样式,因为 函数原型有问题。
It's still valid, but it's pre-ANSI. That's actually where the K&R indent style got its name. The opening bracket is on the line after the function block because this looks weird:
Anyway, this style is not recommended because of a problem with function prototypes.
K&R 风格,我认为它仍然有效,尽管不鼓励。 它可能来自 Fortran(其中函数参数类型仍然在最近的 F95 中定义在函数体内)
K&R style, and I think it's still valid, although discouraged. It probably came from Fortran (where function parameters types are defined inside the function body still in the recent F95)
那是老式的C,现在已经很少见到了。
That's old-style C. It's seldom seen anymore.
这是一个函数原型。 如果你不这样做,你必须在 main 之前完全写出该函数,否则当你在 main 中使用它时,编译器将不知道该函数是什么。 它的描述性不太好,所以不再使用。 你想使用类似的东西:
It's a function prototype. If you didn't do it this way you'd have to write the function out entirely before main, otherwise the compiler wouldn't know what the function was when you used it in main. It's not very descriptive, so it's not used anymore. You'd want to use something like: