本文主要是介绍C89语言标示符名字空间,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
以下摘自:ISO-IEC-9899-1999.pdf 6.2.3
If more than one declaration of a particular identifier is visible at any point in a
translation unit, the syntactic context disambiguates uses that refer to different entities.
Thus, there are separate name spaces for various categories of identifiers, as follows:
— label names (disambiguated by the syntax of the label declaration and use);
— the tags of structures, unions, and enumerations (disambiguated by following any24)
of the keywords struct, union, or enum);
— the members of structures or unions; each structure or union has a separate name
space for its members (disambiguated by the type of the expression used to access the
member via the . or -> operator);
— all other identifiers, called ordinary identifiers (declared in ordinary declarators or as
enumeration constants).
C语言定义了四个彼此独立的名字空间,不同空间里的标示符可以相同而不发生冲突,但是同一名字空间不能有重复的名字。
(1)标签 label单独占用一个名字空间;
(2)struct, union, enum的名字, C术语用tag表示,他们的名字位于同一个名字空间,所以不能同时定义struct tagStudent {...} 和 enum tagStudent{...}。
(3)struct,union的内部成员有相应的struct,uinon声明范围确定一个独立的名字空间。也就是说每一个一个结构体或联合体内部是一个独立的名字空间;
(4)其他的标示符,如变量名字、函数名字、以及enum里的常量名字。
另外:typedef 已知类型 XXX; 其中的XXX应该也是处于自己的名字空间。
这篇关于C89语言标示符名字空间的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!