C89語言標示符名字空間

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.