You cannot use a type before defining it.
When declaring typedef struct tnode { ... } Treenode; the Treenode type Treenode not determined until a semicolon is reached.
The situation with typedef struct tnode *Treeptr; different. This tells the compiler that there is a structure type called struct tnode , and the Treeptr type is an alias for a pointer to struct tnode '. At the end of this declaration, struct tnode is an incomplete type. You can create pointers to incomplete types, but you cannot create variables of an incomplete type (so that you can define Treeptr ptr1; or struct tnode *ptr2; and they are of the same type, but you cannot define struct tnode node; ).
The body of a struct tnode can be written as:
typedef struct tnode { char *word; int count; Treeptr left; Treeptr right; } Treenode;
since Treeptr is a well-known alias for the struct tnode * before the structure is defined. You cannot use Treenode *left; , because Treenode not a known alias until the final semicolon is reached (roughly speaking).
source share