C NamespacesTo 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));
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.