【发布时间】:2012-10-29 11:36:05
【问题描述】:
我正在阅读“C 编程语言”,遇到了关于 struct 的 typedef 的问题。代码是这样的:
typedef struct tnode *Treeptr;
typedef struct tnode { /* the tree node: */
char *word; /* points to the text */
int count; /* number of occurrences */
struct tnode *left; /* left child */
struct tnode *right; /* right child */
} Treenode;
到我们写作的时候
typedef struct tnode *Treeptr;
tnode 还没有被声明,但是我们没有得到任何编译错误, 但是当我们把上面的语句改成:
typedef Treenode *Treeptr;
我们得到编译错误:
error: parse error before '*' token
warning: data definition has no type or storage class
造成这种差异的原因是什么? “struct tnode”不是和“Treenode”一样吗?
【问题讨论】:
标签: c struct typedef declaration