声明和原型差异 [英] Declaration and prototype difference

查看:83
本文介绍了声明和原型差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C语言中声明和原型之间有什么区别?在什么情况下它们称为声明,在哪些原型中?

What is the difference between declaration and prototype in C? In which situations they are called declarations and in which prototypes?

推荐答案

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

TL;DR; All prototypes are declarations, but not all declarations are prototypes.

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

Declaration is the generic terminology used in the standards, prototype is more specific.

引用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章

On the other hand, from chapter §6.2.1

[....] 一个功能 prototype是函数的声明,该函数声明其参数的类型.

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

因此,一个衬里,原型是声明的更完整的形式(包括参数的类型).

So, one liner, prototype is more complete form (including types of parameter) of declaration.

关于标识符":第6.4.2.1节,

About "identifier": chapter §6.4.2.1,

标识符是一系列非数字字符(包括下划线_, 小写和大写拉丁字母,以及其他字符)和数字 6.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章

标识符可以表示一个对象;功能;标签或结构,并集或成员 枚举typedef名称;标签名称;宏名称;或宏参数. [....]

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. [....]

这篇关于声明和原型差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆