Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!bacchus.pa.dec.com!shlump.nac.dec.com!tkou02.enet.dec.com!diamond From: diamond@tkou02.enet.dec.com (diamond@tkovoa) Newsgroups: comp.lang.c Subject: Re: A "How to typedef..." Question Message-ID: <1909@tkou02.enet.dec.com> Date: 9 Aug 90 07:57:38 GMT References: Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa) Distribution: comp Organization: Digital Equipment Corporation Japan , Tokyo Lines: 40 In article fsf@kasparov.scs.com (Rick Farnbach) writes: >How does one create a type, using typedef, that is defined to be a >pointer to a pointer to a pointer... ad infinitum? > tree t; > t[0] = malloc(sizeof(tree)); > t[0][1] = malloc(sizeof(tree)); You need a struct. There is no alternative. >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. You might try: typedef struct _tree { struct _tree *t[2]; } tree; tree t; t.t[0] = malloc(sizeof(tree)); t.t[0].t[1] = malloc(sizeof(tree)); I'm not sure if either might be easier than the other, to convert to C++ and get what you want by overloading operator[]. >Just to pique interest, I add that >PASCAL (blech) *allows* this construct. How can this be done in C? In order to get anything useful out of it in Pascal, you'd have to use a record as well. You can define Type x = ^x; but can't do much with it. [Incidentally, although Mr. C spelled his name using all capitals, and requires you to match his casing, Mr. Pascal didn't.] -- Norman Diamond, Nihon DEC diamond@tkou02.enet.dec.com This is me speaking. If you want to hear the company speak, you need DECtalk.