From: utzoo!decvax!decwrl!turtleva!ken
Newsgroups: net.unix-wizards
Title: Re: structure member names global?
Article-I.D.: turtleva.138
Posted: Tue Feb  1 02:03:27 1983
Received: Wed Feb  2 04:07:34 1983
References: amd70.1343

Sorry, Phil,
	That's just the way your version of the C compiler is.  Subsequent
versions of the compiler have removed this "bug".  You can, however, use the
same structure member name in different structures AS LONG AS they are in the
same position or offset.  For example,
	struct coordinate	{ int x, y; };
	struct three_space	{ int x, y, z; };
	struct coordlist	{
		int x, y;
		struct coordlist *backcord, *forecord;
	};
are all legal.  This results because the C compiler treats members-of-structures
as global to each file.  You could partition your program up into separate
modules in which there are no duplicate members.
	There is an advantage to this, though; one could access data structures
in various ways without going through the bother of declaring a union, as in:
	struct { char byte1, byte0, byte3, byte2; };
	long rambled, scrambled;
	scrambled.byte0 = 'a';
	scrambled.byte1 = x + y / 3;
	scrambled.byte2 = -256;
	scrambled.byte3 = 0;
Newer versions of the compiler are both more flexible and restrictive.  First,
the same structure member names can be used in different structures, regardless
of their position.  Second, variables which are not declared as a particular
structure, cannot use its structure members for referencing.
Although some may prefer the old way, I think most people prefer the newer way
to access structure members.
				Ken Turkowski
				turtlevax!ken