声明和原型的区别

前端之家收集整理的这篇文章主要介绍了声明和原型的区别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
C语句中的声明和原型有什么区别?在哪些情况下,它们被称为声明和原型?

解决方法

TL; DR;所有原型都是声明,但并非所有声明都是原型.

声明是标准中使用的通用术语,原型更具体.

引用C11,章节§6.7

A declaration specifies the interpretation and attributes of a set of identifiers. […]

从§6.7.6开始,

Each declarator declares one identifier,and asserts that when an operand of the same
form as the declarator appears in an expression,it designates a function or object with the
scope,storage duration,and type indicated by the declaration specifiers.

另一方面,从章节6.2.1开始

[….] A function
prototype is a declaration of a function that declares the types of its parameters.

所以,一个班轮,原型是更完整的形式(包括参数类型)的声明.

关于“标识符”:章节§6.4.2.1,

An identifier is a sequence of nondigit characters (including the underscore _,the
lowercase and uppercase Latin letters,and other characters) and digits,which designates
one or more entities as described in 6.2.1. […]

在章节§6.2.1中,

An identifier can denote an object; a function; a tag or a member of a structure,union,or enumeration; a typedef name; a label name; a macro name; or a macro parameter. [….]

原文链接:https://www.f2er.com/c/117002.html

猜你在找的C&C++相关文章