Die erste Form ermöglicht es Ihnen, auf die Struktur zu beziehen, bevor die Typdefinition abgeschlossen ist, so kann man auf die Struktur in sich selbst beziehen oder sich voneinander abhängige Typen:
struct node {
int value;
struct node *left;
struct node *right;
};
typedef struct node Tree;
oder
struct A;
struct B;
struct A {
struct B *b;
};
struct B {
struct A *a;
};
typedef struct A AType;
typedef struct B Btype;
Sie können die beiden wie so kombinieren:
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-in-c – karlphillip
http://stackoverflow.com/questions/252780/why-should-we-typedef-a-struct-so-often-in-c – karlphillip