简体   繁体   中英

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 . In the latter case, you can only reference it as ta since the struct has no tag.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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