07 May 2004

This is a short entry about a specific scoping issue. Consider this code: struct A {int a}; struct B {int b;} If A == B there is a name clash. If a == b there is no name clash because a and b have different scopes. Programers are used to ensure A != B but not used to ensure a != b (they even find it strange in other programming languages: see Caml, Vera, etc.). Now consider this code: enum C { c }; enum D { d }; Now both C == D and c == d will cause a name clash. This is why some "coding style solution" is needed. An option is: enum C { C_c }; enum D { D_d }; Another option is: struct C { enum { c }; }; struct D { enum { d }; }; However the name of an enum (C/D) behaves like the name of a struct. It is one of the reasons most coding standards use the same case convention for enum and struct names.

No comments:

Post a Comment

Note: (1) You need to have third-party cookies enabled in order to comment on Blogger. (2) Better to copy your comment before hitting publish/preview. Blogger sometimes eats comments on the first try, but the second works. Crazy Blogger.