ARM Technical Support Knowledge Articles

USING 2 STRUCTS THAT HAVE POINTERS TO EACH OTHER

Applies to: General Topics

Answer

QUESTION

Is it possible to cross reference two structures with pointers? To do this the compiler must allow declarations of one structure before the second is defined. For example:

struct A {
 struct *bptr;
};

struct B {
 struct *aptr;
};

ANSWER

Yes. This is supported in ANSI C. The following example does compile correctly (with no errors or warnings) under C51 version 5.

struct a
  {
  struct b *ptr;
  };

struct b
  {
  struct a *ptr
  };

Article last edited on: 2004-05-24 21:11:58

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential