Typedef and struct in C

Viewed 65

Is there any difference between those two:

typedef struct ddwq{
    int b;
}ta;

typedef struct {
    int b;
}ta;
1 Answers

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.

Related