[LAD] [ot] programming typedefs...
Dirk Jagdmann
doj at cubic.org
Thu Jul 10 16:47:15 UTC 2008
> But I'mtoo stupid. I have a struct, which contains a pointer to itself as an
> element. How to write this. I once knew, but now I fail. It's a shame! :-(
In C++ Land we do it like this:
struct StupidSolution {
int i;
struct StupidSolution *self;
StupidSolution(int num) : i(num), self(this) { }
};
But maybe you really wanted to do a tree:
struct TreeNode {
int i;
struct TreeNode *parent, *left, *right;
TreeNode(int num, TreeNode *par=NULL) : i(num), parent(par), left(0),
right(0) { }
};
And if you doing it old fashioned in C:
struct StupidSolution {
int i;
struct StupidSolution *self;
};
struct StupidSolution *sol=(struct StupidSolution)malloc(sizeof(struct
StupidSolution));
sol->i=3;
sol->self=sol;
--
---> Dirk Jagdmann
----> http://cubic.org/~doj
-----> http://llg.cubic.org
More information about the Linux-audio-dev
mailing list