C Namespaces

To understvà identifier queries it is best to lớn refresh our notion of theC namespaces.The main way we normally reuse identifier names in C programs isthrough scoping: an identifier within a given scopesuch as a bloông chồng or declared as static within a filewill not interfere with identifiers outside that scope.Thus, the following example will print 3 and not 7.


Bạn đang xem: Namespace c# là gì

CScout analyzes and stores each identifier"s scope performingsubstitutions accordingly.In addition, C also partitions a program"s identifiers into lớn fournamespaces.Identifiers in one namespace, are also considered different fromidentifiers in another.The four namespaces are: Tags for a struct/union/enum Members of struct/union(actually a separate namespace is assignedlớn each struct/union) Labels Ordinary identifiers (termed objects in the C standard)Thus in the following example all id identifier instances aredifferent:
/* structure tag */struct id int id;/* structure member */;/* Different structure */struct id2 char id;/* structure member */;/* ordinary identifier */id()id:/* label */
Furthermore, macro names và the names of macro formal arguments alsolive sầu in separate namespaces within the preprocessor.Normally when you want to locate or change an identifier name,you only consider identifiers in the same scope and namespace.Sometimes however,a C preprocessor macro can semantically unite identifiersliving in different namespaces, so that changes in one of themshould be propagated khổng lồ the others.The most comtháng case involves macros that access structure members.
struct s1 int id; a;struct s2 char id; b;#define getid(x) ((x)->id)main()printf("%d %c", getid(a), getid(b));


Xem thêm: Minh Beta Là Ai - Sự Bùng Nổ Trong Bài Hát Việt Nam Ơi!

In the above example, a name change in any of the idinstances should be propagated to all others for the program toretain its original meaning.CScout understands such changes and will propagate any changesyou specify accordingly.Finally, the C preprocessor"s token concatenation feature can resultin identifiers that should be treated for substitution purposes inseparate parts.Consider the following example:
int xleft, xright;int ytop, ybottom;#define coord(a, b) (a ## b)main()printf("%d %d %d %d ",coord(x, left),coord(x, right),coord(y, top),coord(y, bottom));
In the above example, replacing x in one of the coordmacro invocations should replace the x part in thexleft và xright variables.Again CScout will recognize and correctly handle this code.
*



Xem thêm: Tìm Hiểu Chung Về Phép Lập Luận Là Gì ? Phép Lập Luận Giải Thích Là Gì

Last change: Friday, April 12, 2019 1:33 pm Unless otherwise expressly stated, all original material on this page created by Diomidis bigbiglands.com is licensed under a Creative Commons Attribution-Share Alượt thích 3.0 Greece License.

Chuyên mục: Ý NGHĨA
Bài viết liên quan

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *