A "How to typedef..." Question

Rick Farnbach fsf at kasparov.scs.com
Tue Aug 7 12:25:18 AEST 1990


How does one create a type, using typedef, that is defined to be a
pointer to a pointer to a pointer... ad infinitum?  The straight-forward
approach is:

     typedef tree *tree[2];     /* binary tree, for example */

Which is, of course, grossly illegal.  What I would like to be able to
do is write lines such as:

    tree t;

    t[0] = malloc(sizeof(tree));
    t[0][1] = malloc(sizeof(tree));
         .
         .
         .

The closest I have been able to do is:

    typedef struct _tree {
        struct _tree *t;
    } tree[2];

    tree t;

    t[0].t = malloc(sizeof(tree));
    t[0].t[1].t = malloc(sizeof(tree));
        .
        .
        .

Which is *not* what I am after.  Just to pique interest, I add that
PASCAL (blech) *allows* this construct.  How can this be done in C?

Thanks,
Rick

NOTE: Please do not waste bandwidth telling the whole network that *you*
can't see any reason for wanting to do this.  If you don't have an
answer then keep your (computer) shut!



More information about the Comp.lang.c mailing list