以下摘自: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應該也是處於自己的名字空間。