查看文章 |
struct vs typedef struct
2008-06-19 14:45
常见的结构定义方式有以下两种: struct id{...}; (1) typedef struct {} id; (2) 二者的区别在于(1)中的id是一个tag,(2)中的id是一个type,具体体现在定义变量时: struct id v1; id v1; 二者还有些细微的差别,当定义linked list时,在结构体中需引用结构名,如下: struct list{ ... struct list* next; }; 若用第二种形式 typedef struct { ... list* next; } list; 编译器会警告list未定义,一个折中的办法是 typedef struct _list{ ... struct _list* next; } list; 以上讨论仅对c有效 |
最近读者: