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应该也是处于自己的名字空间。

你可能感兴趣的:(c,struct,Access,语言,structure,Constants)