La première forme vous permet de faire référence à la struct avant la définition de type est terminée, vous pouvez donc se référer à la struct en lui-même ou avoir des types mutuellement dépendants:
struct node {
int value;
struct node *left;
struct node *right;
};
typedef struct node Tree;
ou
struct A;
struct B;
struct A {
struct B *b;
};
struct B {
struct A *a;
};
typedef struct A AType;
typedef struct B Btype;
Vous pouvez combiner les deux comme ceci:
typedef struct node {
int value;
struct node *left;
struct node *right;
} Tree;
typedef struct A AType; // You can create a typedef
typedef struct B BType; // for an incomplete type
struct A {
BType *b;
};
struct B {
AType *a;
};
http://stackoverflow.com/questions/1083959/purpose-of-stru ct-typedef-struct-en-c – karlphillip
http://stackoverflow.com/questions/252780/why-should-we-typedef-a-struct-so-often-in-c – karlphillip