Questions about Dictionary Project?

Mutually dependent structs

Mutually dependent structs

by Nidal Jaafar -
Number of replies: 1
Picture of GroupEn

Doctor, consider these two structures

struct A
{
    int a;
    struct B b;
};
 
struct B
{
    int b;
    struct A a;
};

This code obviously gives a compile error, how can we address this type of problems? Can we provide a structure prototype, similar to a function prototype when using two dependent functions?

In reply to Nidal Jaafar

Re: Mutually dependent structs

by Siba Haidar -

Yes Nidal we can provide a structure prototype. But here, this will not resolve the issue because those are not only mutually dependant structures but also recursive structures. 
It they had fields that point to each other it ok. But the case you cited is not permitted because the compiler would never be able to know how many bytes to reserve for such variables. (infinite nesting!)