在函数名之后声明函数参数

发布于 2024-07-27 20:46:00 字数 123 浏览 6 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不即不离 2024-08-03 20:46:00

即 K&RC 参数声明语法,该语法在 ANSI C 中有效,但在 C++ 中无效。

That is K&R C parameter declaration syntax, which is valid in ANSI C but not in C++.

澜川若宁 2024-08-03 20:46:00

它仍然有效,但它是 ANSI 之前的版本。 这实际上就是 K&R 缩进样式得名的地方。 左括号位于功能块后面的行上,因为这看起来很奇怪:

int func(x)
int x; {
...
}

无论如何,不​​推荐这种样式,因为 函数原型有问题

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:

int func(x)
int x; {
...
}

Anyway, this style is not recommended because of a problem with function prototypes.

箹锭⒈辈孓 2024-08-03 20:46:00

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)

毅然前行 2024-08-03 20:46:00

那是老式的C,现在已经很少见到了。

That's old-style C. It's seldom seen anymore.

梦太阳 2024-08-03 20:46:00

这是一个函数原型。 如果你不这样做,你必须在 main 之前完全写出该函数,否则当你在 main 中使用它时,编译器将不知道该函数是什么。 它的描述性不太好,所以不再使用。 你想使用类似的东西:

int someFunction(int someParamX int someParamY);

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:

int someFunction(int someParamX int someParamY);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文