1

Consider the following C struct:

struct person {
    char *name;
    unsigned int age;
};

In many samples of C code that I have recently come across, I have seen structs instead declared in the following manner:

typedef struct {
    char *name;
    unsigned int age;
} person_t;

Other than brevity in that a declaration can then be made as person_t bob rather than struct person bob, is there any advantage to doing this? Furthermore, what is the standard convention within the C community for when do declare a struct the normal way versus when to declare it within a typedef?

Ryan
  • 7,621
  • 5
  • 18
  • 31

0 Answers0