1.struct tag:
定义一个struct:
struct tag {
int a;
int b;
} Tag1;
这里的tag只是一个标签,并不是类型,而struct tag才是一个完整的类型,定义变量需要:
struct tag variable;
而上面的Tag1在定义struct结构体的时候定义的一个变量。
2.typedef struct:
typedef struct {
int a;
int b;
}name;
这里的name是一个struct类型的别名,可以用来直接定义变量,比如:
name variable2;
上面的struct本身是一个匿名的struct。
3.typedef struct tag :
typedef struct tag {
int a;
int b;
}name;
相当于先定义struct tag,然后typedef起别名一样。
可以使用
name variable3;
struct tag variable4;
来定义变量。
区别是typedef struct之后定义变量只能用name,而typedef struct tag的话,之后定义变量可以name也可以struct tag。