typedef a struct before it's declared

前端 未结 7 1942
死守一世寂寞
死守一世寂寞 2020-12-09 15:14

I\'m not a beginner, I\'m very familiar with the following idiom:

typedef struct Foo_ Foo;// I know typedef struct Foo Foo is fine, I\'m just trying to make          


        
7条回答
  •  Happy的楠姐
    2020-12-09 15:33

    typedef is used to create an alias for a type. But that type doesn't necessarily exist when typedef'ed.

    For example,

    if you just do:

    struct Foo;
    

    and you never define the struct Foo anywhere in the program, then it'll still compile. Compiler would assume it's defined somewhere and continue. Only if you use it without defining the struct, an error will occur.

    It's the similar case with typedef as well.

提交回复
热议问题