In article <37*************@individual.net>
S.Tobias <si***@FamOuS.BedBuG.pAlS.INVALID> wrote:
typedef int myint;
struct s
{
myint myint; /* 1 */
} s;
int main()
{
myint myint; /* 2 */
s.myint = 5; /* 1 */
myint = 1; /* 2 */
return myint; /*kill warning*/
}
What is interesting to me is case 2. "Typedef myint" and "object myint"
identifiers belong to the same name space, so I think there should
be a conflict (there's no conflict in case 1 - members have a name
space of their own). However, two compilers accepted the above code.
They are indeed in the same name-space; but the declaration of the
block-scope variable in "2" is in an inner scope, which hides the
outer-scope name. This is therefore no different than:
int i;
int f(void) {
int i;
...
}
or, perhaps even closer but C99-specific:
int i;
int f(void) {
i = 3; /* sets the file-scope i */
int i = 2; /* creates a new i */
i = 1; /* sets the block-scope i */
...
}
(Actually *implementing* "myint myint;" in C compilers tends to be
pretty tricky, while implementing the scoped "i"s tends to be easy,
but this is an artifact of typical C implementations.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.