Declaration rule in struct typedef

前端 未结 3 1104
我寻月下人不归
我寻月下人不归 2020-12-19 09:23

I\'m reading \'The C Programming Language\' and encountered a problem about typedef of struct. The code is like this:

typedef struct tnode *         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 09:35

    A line typedef struct tnode *Treeptr; has implicit forward declaration of "tnode" struct. It's similar to:

    typedef struct tnode Treenode;
    typedef Treenode *Treeptr;
    
    struct tnode { /* the tree node: */
        char *word; /* points to the text */
        int count; /* number of occurrences */
        struct tnode *left; /* left child */
        struct tnode *right; /* right child */
    };
    

提交回复
热议问题