And*_*ell 16 c terminology forward-declaration function-prototypes
对我来说,这些术语在使用C编程语言时基本上是同义词.在实践中,我可能更喜欢文件内原型的"前向声明"而不是通过头文件包含的原型的"函数原型".但是当你考虑预处理后发生的事情时,即使这是一个人为的区别.也许我错过了一些东西.
关于何时使用一个术语而不是另一个术语是否存在共识?
术语"原型"是指特定的声明语法; 具体而言,函数的参数数量和类型出现在声明中.给定一个函数定义的
int foo(int a, char *b) {...}
Run Code Online (Sandbox Code Playgroud)
您可以使用以下任何声明:
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
Run Code Online (Sandbox Code Playgroud)
IMO那些不是真正的同义词.对我来说,"函数原型"是指函数名称及其参数'和返回的类型.它不仅适用于您所谓的"前向声明".所有功能都有原型.
我们经常在函数声明和相应的定义之间做出改变.
我将前向声明一词用于以下struct带有定义的声明。
struct Foo;
Run Code Online (Sandbox Code Playgroud)
为了与1989年以前的(K&R)C兼容,函数声明不必是完整的原型。
char *foo(); // NOT the same as char *foo(void)
Run Code Online (Sandbox Code Playgroud)