The C spec says
There are four kinds of scopes: function, file, block, and function prototype.
Now if I do the following outside any
I think the scope it refers to in this case is A. You refer to the member by SomeA.x, where SomeA is of type A.
As the standard says, it's in a separate name space created for the struct
type. This rule was added in C89, I think. Once upon a time, all member names shared a single name space.
Maybe the compiler writer was being pedantic; a name space is not the same as a scope. A struct
definition does not introduce a scope as it doesn't hold variables; it holds members.
Scope and name space are two entirely different concepts and should not be confused.
An instance of a struct or union has scope, but the individual member names do not; the concept of scope simply doesn't apply to them.
Argh, I was thinking in terms of extent, not scope.
x
is in the scope created by struct A
, but A
is in global scope. This is what the "spec" calls file-scope but the name is misleading because all files that you include share that scope.