定义
它识别与变量、函数、类等名称相关的代码或数据。编译器本质上需要定义来为声明的实体指定存储区域。当一个变量被定义时,它有一个包含该变量的多个字节的内存量。
函数定义为函数生成代码。它只能在一个程序中定义一个程序元素一次,因为该定义是一个程序元素的唯一要求。声明和定义之间的关系可以是一对多的。
宣言
它可以确定程序的名称,包括变量、函数、命名空间、类等的名称。没有声明就不能在程序中使用名称。
程序元素可以使用不同的定义多次声明。仅当使用精确格式形成多个声明时,才能生成各种声明。从编译器的角度来看,声明是支持程序元素的可感知性的媒介。
让我们看看定义和声明之间的比较。
定义 | 声明 | Thedefinitionspecifiesattributesandcausesstorageallocation.
| 该声明指定类型和不同的属性,但不生成存储分布。
|
Thedataincludedinthedefinitionisonlyusedduringtranslation.Thelanguagetranslatorentersthedatafromthetypedefinitionintothetableduringtranslationandwheneverthetypenameisreferencedinasuccessivedeclaration,usedthetableddatatocreatethesuitableexecutableprogramforsettingupandmanipulatingthedesiredinformationobjectsduringexecution.
| 变量声明中包含的数据主要在翻译过程中用于决定信息对象的存储表示以及存储管理和类型检查目标。
|
Foraparticularname,aCprogramcanhaveonlyasingledefinition.
| 对于特定名称,C程序可以有各种兼容的声明。
|
Thetypedefinitionenablessomeelementsoftranslationincludingdecidingstoragerepresentationstobecompletedonlyonceforasingletypedefinition.
| 类型声明多次确定不同声明的存储表示。
|
Theinclusionoftypedefinitionsinalanguagedoesnotgenerallymodifytheruntimeorganizationofthelanguageexecution.
| 在语言中包含类型定义可能会改变语言的运行时组织,因为它们用于设置运行时数据对象。
|