Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!uwvax!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: mutual reference in structures Message-ID: <17441@mimsy.UUCP> Date: 11 May 89 11:20:54 GMT References: <6712@medusa.cs.purdue.edu> <1822@ubu.warwick.UUCP> <2346@wheat-chex.ai.mit.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 51 In article <2346@wheat-chex.ai.mit.edu> jym@wheaties.ai.mit.edu (Jym Dyer) writes: >VAX C accepts this (which seems wrong to me): > > typedef struct > { > struct NODE_T * flink_p; > struct NODE_T * blink_p; > char data[512]; > } NODE_T; This is legal; it is merely stupid. It is the moral equivalent of typedef struct { struct never_defined *forw; struct never_defined *back; char data[512]; } NODE_T; Here, you cannot use the pointers `forw' and `back' without first declaring a structure tag `struct never_defined'. In the quoted article, you cannot use the pointers `flink_p' and `blink_p' because there is no `struct NODE_T' (there is only a NODE_T; the typedef is in a different namespace from structure tags). >It would be nice if C typedefs knew about themselves ... : > > typedef > { > NODE_T * flink_p; > NODE_T * blink_p; > char data[512]; > } NODE_T; This would require the ability to `back up', or at least to defer `thinking about' the declaration. There is nothing in C that now requires this, so it would be in effect a radical change. What is so wrong with typedef struct node_t { struct node_t *flink_p; struct node_t *blink_p; char data[512]; } NODE_T; anyway? -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris