I could not come to the reason why i m getting compilation error to this code?Would be great help if someone clarified it.
int main()
{
struct xx
{
int x;
struct yy
{
int z;
struct xx *p;
};
struct yy *q;
};
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In C language you are not allowed to declare
structtypes inside otherstructtypes without immediately introducing a data field. I.e. struct declaration and data field declaration should be done in one step (as one declaration). You violated that rule: yourstruct yydefinition just sits insidestruct xxdefinition for no reason whatsoever.Either pull the
struct yydefinition outside ofstruct xx, or make sure thatstruct yydefinition immediately declares a field ofxx.For example, this implements the same intent, but does it correctly
However, usually in C language there’s no reason to create nested struct definitions. It is usually a better idea to define structs at the same level, without any nesting
Why didn’t you do it that way from the beginning? What was the point of defining these structs in “nested” fasion?