简体   繁体   English

C中的Typedef和struct

[英]Typedef and struct in C

Is there any difference between those two: 这两者之间有什么区别:

typedef struct ddwq{
    int b;
}ta;

typedef struct {
    int b;
}ta;

In the former case, you can reference the type of the struct as either struct ddwq or ta . 在前一种情况下,您可以将结构的类型引用为struct ddwqta In the latter case, you can only reference it as ta since the struct has no tag. 在后一种情况下,您只能将其引用为ta因为struct没有标记。

The first case is required if the struct will contain a pointer to itself such as: 如果结构将包含指向自身的指针,则需要第一种情况,例如:

typedef struct ddwq{
    int b;
    struct ddwq *p;
}ta;

The type name ta isn't visible inside of the struct, so the struct must have a tag name for it to reference itself. 类型名称ta在结构内部不可见,因此结构必须具有标记名称才能引用它自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM