C中的Typedef和struct

Leo*_*sky 3 c struct typedef

这两者之间有什么区别:

typedef struct ddwq{
    int b;
}ta;

typedef struct {
    int b;
}ta;
Run Code Online (Sandbox Code Playgroud)

dbu*_*ush 7

在前一种情况下,您可以将结构的类型引用为struct ddwqta.在后一种情况下,您只能引用它,ta因为struct没有标记.

如果结构将包含指向自身的指针,则需要第一种情况,例如:

typedef struct ddwq{
    int b;
    struct ddwq *p;
}ta;
Run Code Online (Sandbox Code Playgroud)

类型名称ta在结构内部不可见,因此结构必须具有标记名称才能引用自身.