问:如下,我定义了一个链表头,为什么编译报错?
error: unknown type name ‘node_t’
#include <stdio.h>
#include <stdint.h>
#include <string.h>
typedef struct _node{
void * item;
node_t * next;
}node_t;
int main(int argc, char* argv[])
{
return 0;
}
答:typedef定义了一个新的类型名,但是不能在定义类型名之前使用它。可以按如下修改代码:
#include <stdio.h>
#include <stdint.h>
#include <string.h>
typedef struct _node{
void * item;
struct _node * next;
}node_t;
int main(int argc, char* argv[])
{
return 0;
}