Declaration rule in struct typedef

前端 未结 3 1102
我寻月下人不归
我寻月下人不归 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条回答
  •  臣服心动
    2020-12-19 09:43

    When you declare TreePtr, you are not implementing the struct. That is known as a "forward declaration". Something like: "here we use this, but later I will explain it better". The implementation must appear later, only once, and that is what you find in the second typedef.

    And TreePtr is not the same as the struct, because TreePtr will be in fact a new type that includes the fact of beeing a pointer.

提交回复
热议问题