My question is why typedef needs flight to be written a second time at the end of a block?
When you declare:
typedef struct flight{
int number;
int capacity;
int passengers;
}flight;
you actually declare two things:
- a new structure type
struct flight
- a type alias name
flight
forstruct flight
.
The reason why the type alias name with typedef
appears at the end of the declaration like for any ordinary declaration is because for historical reasons typedef
was put in the same specifiers category as storage-class specifiers (like static
or auto
).
Note that you can just declare:
typedef struct {
int number;
int capacity;
int passengers;
}flight;
without the tag name if you intend to only use the type identifier flight
.