Re: loop in strucures definition



riccardo <riccardo@xxxxxxxxx> wrote:

typedef struct {
foo2 a;
} foo1;

typedef struct {
foo1 b;
} foo2;

foo2 is not defined yet when used to define foo1.
Placing the foo2 definition before foo1 doesn't help of course.
How can I solve this in a clean way?

Method 1:

typedef struct foo1 {
struct foo2 a;
} foo1;

typedef struct foo2 {
struct foo1 b;
} foo2;

Method 2:

typedef struct foo1 foo1;
typedef struct foo2 foo2;
struct foo1 {
foo2 a;
};

struct foo2 {
foo1 b;
};
--
Larry Jones

Hmph. -- Calvin
.



Relevant Pages

  • Re: loop in strucures definition
    ... foo2 is not defined yet when used to define foo1. ... Placing the foo2 definition before foo1 doesn't help of course. ...
    (comp.lang.c)
  • Re: loop in strucures definition
    ... foo2 is not defined yet when used to define foo1. ... Did you read the two-level Algol 68 grammar? ...
    (comp.lang.c)
  • Re: loop in strucures definition
    ... foo2 is not defined yet when used to define foo1. ... Now, if instead of the box including another box, it includes a piece of paper telling you where another box may be found, then this infinitely-recursive definition never occurs. ...
    (comp.lang.c)
  • Re: loop in strucures definition
    ... foo2 is not defined yet when used to define foo1. ... Placing the foo2 definition before foo1 doesn't help of course. ...
    (comp.lang.c)
  • loop in strucures definition
    ... foo2 is not defined yet when used to define foo1. ... Placing the foo2 definition before foo1 doesn't help of course. ...
    (comp.lang.c)