scope of a structure tag

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Jan 7 11:54:53 AEST 1989


In article <18799 at agate.BERKELEY.EDU> holub at violet.berkeley.edu () writes:
-I'm confused about the scope of a structure tag. Is the following legal
-in ANSI C:
-	struct tag1
-	{
-		struct tag2
-		{
-			int a, b;	
-		} x;
-	}
-	struct tag3
-	{
-		struct tag2 y;
-	}
-or does the inner structure have to be redefined in tag3?

I don't understand your example, which is syntactically invalid.
Assuming you put semicolons where they belong and that the two
"outer" structures are declared within the same scope (the same
file, block, or function prototype, depending on the context),
then the first "struct tag2" is still in scope when the second
one is encountered, so it is a complete type at that point.



More information about the Comp.std.c mailing list