tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: UVM typedef struct
On Thu, 13 Aug 2009, Tonnerre LOMBARD wrote:
> I mean:
>
> typedef struct {
> ...
> blubb_t blubbs[MAX_BLUBBS];
> ...
> } bla_t;
>
> typedef struct {
> ...
> bla_t owner;
> ...
> } blubb_t;
As James said, you can't do exactly that as two structures cannot fully
contain each other (mumble .. laws of physics :).. but your original
message said something different:
> - bla_t contains a list of references to blubb_t
> - blubb_t contains a pointer back to bla_t
So, you just need to declare the structure name first and define the
structure content afterwards which requires a structure tag:
typedef struct bla bla_t;
typedef struct blubb blubb_t;
struct bla {
...
blubb_t blubbs[MAX_BLUBBS]; /* array of blubbs */
...
blubb_t *pblubs[MAX_BLUBBS]; /* array of pointers */
...
};
struct blubb {
...
bla_t *owner; /* pointer to bla is ok */
...
};
you are not obliged to use "blubb" and "bla" again and the structure
namespace is separate so it won't collide with anything else.
or if you wanted only pointers you could typedef the pointer:
typedef struct bla * bla_t;
typedef struct blubb * blubb_t;
struct bla {
...
blubb_t blubbs[MAX_BLUBBS]; /* array of pointers */
...
};
struct blubb {
...
bla_t owner; /* pointer to bla */
...
};
but as noted elsewhere that is flirting with obfustication (which may be
the intention in an interface that provides a 'cookie')
iain
Home |
Main Index |
Thread Index |
Old Index