Struct definition in MS-C

Fred Smith fredex at cg-atla.UUCP
Thu Aug 17 23:03:09 AEST 1989


In article <Aug.16.14.48.38.1989.11505 at caip.rutgers.edu> shuang at 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



More information about the Comp.lang.c mailing list