Reading from Nested structures, I realized that structure declared within another structure is scoped the same as the containing structure. I thought it is only scoped within the containing structure. I got this impression from this link. It says there are 4 namespaces and one of them is members of a structure. I "logically" inferred that inner structures are only scoped within the outer one.
Can anyone provide a reference to the standard as to exactly how the scope rule works in this case? And any rationale for allowing inner struct to be visible outside the containing structure? If it is visible, why not just declare the struct outside...
Question 2: For terminology, when I provide the members of a structure, say
struct out{
int a, b;
char c, d;
struct in{
int a, b;
}e;
};
Am I providing a definition for both struct out
and struct in
; OR am I providing a declaration for both? I understand the difference for functions and primitive data types but not really clear here for struct s.
EDIT: Useful link I just found on SO: Nested structures in C and C++.
But there it does not provide any rationale. And now I doubt if there is one for C...