Questions about Dictionary Project?

Mutually dependent structs

Mutually dependent structs

par Nidal Jaafar,
Nombre de réponses : 1
Avatar 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?

En réponse à Nidal Jaafar

Re: Mutually dependent structs

par 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!)