Path: utzoo!utgpu!watmath!att!bellcore!rutgers!iuvax!cica!ctrsol!ginosko!cg-atla!fredex From: fredex@cg-atla.UUCP (Fred Smith) Newsgroups: comp.lang.c Subject: Re: Struct definition in MS-C Keywords: pointer, linked list, Microsoft C Message-ID: <7529@cg-atla.UUCP> Date: 17 Aug 89 13:03:09 GMT References:Reply-To: fredex@cg-atla.UUCP (Fred Smith) Organization: Agfa Compugraphic Division Lines: 44 In article shuang@caip.rutgers.edu (Shuang Chen) writes: > > >I am trying to use struct to implement a linked list with Microsoft C. >The problem I had was that I could not define a node structure with a >pointer to point to another node of the same type. The program was > >typedef struct { > > ... > ... > node *next; > } node; > > ------------------------ I have done exactly what you want by doing the following, which is much like examples in K&R (1st edition) page 131 and page 140: typedef struct node { ... ... node *next; } NODE, *PNODE; After doing this is is possible to declare data entities of type NODE, which allocates the space for such a structure, and as type PNODE, which allocates space for a pointer to such a structure. This works. I have done it numerous times. The problem with the example you gave (reproduced above) is that the structure definition contains an item of type pointer to node, but at that point the compiler does not yet know what a node is. I suggest you check out chapter 6 of K&R (1st Ed) for examples and discussion. Good luck! Fred Smith