| ||||||||
Technical Support Support Resources Product Information | GENERAL: FORWARD STRUCTURE REFERENCES IN CInformation in this article applies to:
QUESTIONHow can I create several structures that reference each other. It appears that there is a problem with C understanding forward recerences to structures. For example, the following code:
struct a
{
struct b *pb;
};
struct b
{
struct a *pa;
};
struct a a1 = { &b1 };
struct b b1 = { &a1 };
Generates the following error: *** ERROR C202 IN LINE 12 OF .\JJ.C: 'b1': undefined identifier How do I do this in C? ANSWERChange your code to the following to use forward struct references.
struct a
{
struct b *pb;
};
struct b
{
struct a *pa;
};
struct b b1; /* declare the b1 but don't define it -- this makes it work */
struct a a1 = { &b1 };
struct b b1 = { &a1 };
Last Reviewed: Thursday, April 27, 2000 | |||||||
| ||||||||