Kai*_*kha 1 c syntax function-declaration
在研究函数声明时,我遇到了一种(对我来说)奇怪的函数定义方式:
int f(void); // declaration: takes no parameters
int g(); // declaration: takes unknown parameters
int main(void) {
f(1); // compile-time error
g(2); // undefined behavior
}
int f(void) { return 1; } // actual definition
int g(a,b,c,d) int a,b,c,d; { return 2; } // actual definition
Run Code Online (Sandbox Code Playgroud)
最后一行完全让我困惑。这是什么int g(a,b,c,d) int a,b,c,d; { return 2; }意思?这样的问题可能已经被问过,但我不知道如何组成搜索查询。
的定义g使用旧的 K&R 方法来指定参数类型。
(不是在and内部指定参数及其类型),而是仅指定名称,然后指定参数的类型,然后指定函数体。
这种声明参数的方式已被弃用,不应再使用,因为除其他原因外,它也不符合函数原型的资格。
| 归档时间: |
|
| 查看次数: |
253 次 |
| 最近记录: |