What is the difference between structure and function scope in C?
c, struct
Solution
In upper example member `s` is a local to struct. You cannot use it without using `t.s` syntax, so there is no conflict with structure type `s`.
In lower example structure type `s`, and variable `s` are in the same scope, so it is unclear which you are referring to.
Problem
Consider this piece of code ``` int main(void) { typedef struct { int i; } s; struct { s s; } t; return 0; } ``` It compiles fine. Now take a look at this one ``` int main(void) { typedef struct { int i; } s; s s; return 0; } ``` This code will not compile - ``` ‘s’ redeclared as different kind of symbol. ``` Question: Why is it correct to have "s s;" as a declaration inside a structure, but not correct to have this definition inside a function?