| ARM Technical Support Knowledge Articles | |
Applies to: General Topics
Information in this article applies to:
How 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?
Change 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 };
Article last edited on: 2000-04-27 00:00:00
Did you find this article helpful? Yes No
How can we improve this article?