Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!sdcsvax!ucbvax!hoptoad!gnu From: gnu@hoptoad.uucp (John Gilmore) Newsgroups: comp.lang.c Subject: Question on scope of struct/union tags Message-ID: <3723@hoptoad.uucp> Date: 23 Dec 87 02:03:11 GMT Organization: Nebula Consultants in San Francisco Lines: 36 I am testing compilers and need clarification on the exact scope of declarations. The 1 Oct 86 dpANS says, in section 3.1.2.1, that a declaration's scope extends from the end of its *declarator* to the end of the block or source file. The question is, what if the identifier is not declared by a *declarator*, but by a *struct-or-union-specifier*. An example is the tag "s" in the second definition below: struct s {int x[5];}; foo() { struct s {struct s *next; int i;}; static struct s sa[2]; bar(sa[0].next->x[4]); bar(sa[0].next->i); } I have two "ANSI" compilers (GCC and High-C); each accepts one of the above calls to bar() and calls the other an error. The question is which one is "right". I would prefer if the tag "s" was redefined immediately after its appearance, so it can be used inside the {...} to make a self- referential structure. This seems like what most people would expect. It also gives the same result as when there is no global "struct s". The 1 Oct 86 standard does not seem to require this result, though. As required by the standard, both compilers use the inner definition of "s" if the line "struct s;" is inserted just after the { that opens foo(). -- {pyramid,ptsfa,amdahl,sun,ihnp4}!hoptoad!gnu gnu@toad.com I forsee a day when there are two kinds of C compilers: standard ones and useful ones ... just like Pascal and Fortran. Are we making progress yet? -- ASC:GUTHERY%slb-test.csnet