C Namespaces

To understand identifier queries it is best khổng lồ 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 blochồng or declared as static within a filewill not interfere with identifiers outside that scope.Thus, the following example will print 3 và 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 inlớ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 assignedto lớ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 and the names of macro formal arguments alsolive in separate namespaces within the preprocessor.Normally when you want khổng lồ 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 lớn 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: What Is The Meaning Of " Hey Guy Là Gì, Cho Hỏi Cách Dùng Chữ Guy Trong Tiếng Anh

In the above sầu example, a name change in any of the idinstances should be propagated lớn 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 and xright variables.Again CScout will recognize và correctly handle this code.

Last change: Friday, April 12, 2019 1:33 pm Unless otherwise expressly stated, all original material on this page created by Diomidis hjwitteveen.com is licensed under a Creative sầu Commons Attribution-Share Alike 3.0 Greece License.
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 *