Is typedef ever required in C?

前端 未结 15 2836
夕颜
夕颜 2021-02-13 14:19

Typedef is very useful for portable names, tag names (typedef struct foo Foo;) and keeping complicated (function) declarations readable (typedef int (*cmpfunc

15条回答
  •  有刺的猬
    2021-02-13 15:02

    Without typedef, you have to use the keyword struct everytime if you use a struct in declarations. With typedef, you can omit this.

    struct Person
    {
      char * name;
    };
    
    struct Person p; /* need this here*/
    
    typedef struct _Person
    {
      char * name;
    } Person;
    
    Person p; /* with typedef I can omit struct keyword here */
    

提交回复
热议问题