Struct definition in MS-C

Larry Breed lmb at ibmpa.UUCP
Thu Aug 24 08:03:19 AEST 1989


In article <1989Aug18.101819.3634 at twwells.com> bill at twwells.com (T. William Wells) writes:
>
>struct node {
>	...
>};
>foo()
>{
>	struct node {
>		struct node *next;
>	};
>
>The "struct node *" is, I think, going to refer to the global struct
>node, not the local one; in that case, adding an additional "struct
>node;" at the start of the function will fix things.

The struct node defined in foo has scope starting at the left brace of
its declaration.  (pANS 3.1.2.1 paragraph 5.)  This was true in K&R C
as well.  Therefore the "struct node *" refers to the local struct node.

This odd rule for where scope begins is the reason for the curious
statement (3.1.2.1 para 4):

  "Two identifiers have the same scope if and only if the scopes
   terminate at the same point."

It has to be described this way because every identifier's scope
starts at a different point.

-- 
Larry Breed
inet: lmb%ibmsupt at uunet.uu.net
uucp: uunet!ibmsupt!lmb		(415) 855-4460



More information about the Comp.lang.c mailing list