C 标准 - 函数定义是函数原型吗?
标准(最新版本:WG14/N1256)表示(6.2.1 §2):
函数原型是函数的声明,它声明了其参数的类型。
在此语句附近,我们还发现了标识符声明由声明符或类型说明符组成的证据 (§4):
每个其他标识符的范围由其声明的位置决定(在一个 声明符或类型说明符)。
因此,了解函数定义是否是函数原型似乎可以归结为了解函数定义是否是声明符。是吗?
我需要一个符合 C 标准的经过验证的答案。我并不真正关心通常的含义,或者维基百科或你最喜欢的 C 书的内容。
以下是标准中的声明,使我认为函数定义确实可以是函数原型(§4):
如果声明标识符的声明符或类型说明符出现在函数原型(不是函数的一部分)的参数声明列表中 定义),...
The standard (latest version : WG14/N1256) says (6.2.1 §2) :
A function prototype is a declaration of a function that declares the types of its parameters.
In the vicinity of this statement, we also find evidence that an identifier declaration consist of a declarator or a type specifier (§4) :
Every other identifier has scope determined by the placement of its declaration (in a
declarator or type specifier).
So it would seem that knowing if a function definition is a function prototype boils down to knowing if a function definition is a declarator. Is it ?
I need a proven answer that is in conformance to the C standard. I don't really care about the usual meaning, or what Wikipedia or your favorite C book says.
Here is the statement in the standard that led me to think that function definitions can indeed be function prototypes (§4) :
If the declarator or type specifier that declares the identifier appears within the list of parameter declarations in a function prototype (not part of a function
definition), ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,请参阅 6.9.1 关于函数定义的第 7 段:
Yes, see 6.9.1 about function definitions, paragraph 7: