对我来说,在使用 C 编程语言时,这些术语本质上是同义词。在实践中,我可能更喜欢文件内原型(prototype)的“前向声明”而不是通过头文件包含的原型(prototype)的“函数原型(prototype)”。但是,当您考虑预处理后发生的情况时,这甚至是人为的区别。也许我遗漏了什么。
对于何时使用一个术语与另一个术语是否达成共识?
最佳答案
术语“原型(prototype)”是指特定的声明语法;具体来说,函数参数的数量和类型出现在声明中。给定一个 定义 的函数
int foo(int a, char *b) {...}
您可以拥有以下任何声明:
int foo(); // a declaration, but not a prototype
int foo(a, b); // a declaration, but not a prototype
int foo(int, char *); // a declaration and a prototype
int foo(int a, char *b); // a declaration and a prototype
关于c - 术语:前向声明与函数原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8496284/