I am testing mutual referential structure pointers( which is used for thread lib later). the code can't compiled, keep reminding me add 'qualifer-list' before B_t
#include#includetypedef struct A{
int id;
B_t b;
}*A_t;
typdef struct B{
int id;
A_t a;
}*B_t;
int main()
{
return 0;
}
I tried to add 'B_t' just after header files but doesn't work.
Any idea is well apprecaited! Thanks you guys.
Kunsheng
Comments
This is what I would have done:
[code]typedef struct A{
int id;
A a;
Specifics specifics;
} A_t;
[/code]
If A and B are different, store the differencies in the "specifics" variable.
: #include
: #include
:
: typedef struct A{
:
: int id;
: B_t b; /* struct B *b; */
: }*A_t;
:
: typdef struct B{
:
: int id;
: A_t a; /* struct A * a */
: }*B_t;
:
:
If an A contains a B then a B cannot, tardis-fashion, contain an A. That's a basic feature of data structures.
However A and B can contain pointers to each other. One of the quirks of C is that the compiler won't look ahead to the typedef. So you need to put the struct keyword in the definition of A, and it's neater though not required to hav it in B as well.
My situation is awful. I have a structure thread and a structure thread_queue. thread_queue, of course, contains a pointer to a structure thread.
At the same time, a structure thread contains a pointer to a thread_queue (which record the threads waiting for its returnvalue). Also I am forced to use 'typdef struct A{ ... }*A_t' here.
My code is complete as below. Both 'A_t' and 'B_t' are structure pointers.
it keep reminds me
'structure.c:9: error: expected specifier-qualifier-list before