我正在尝试使用 C(不是 C++)创建链接列表。链接列表通过函数 llinit() 初始化,该函数应该返回一个列表结构。但是,当我编译代码时,我在 lltester.c 文件中收到一条错误消息,指出“错误:无效初始化程序”。为什么是这样?
这是用于在我的 llist.c 文件中初始化链表的函数:
list llinit()
{
list* ll = malloc(sizeof(list));
ll->head = NULL;
ll->tail = NULL;
return *ll;
}
这是我的 llist.h 文件中的列表结构:
typedef struct {
node *head;
node *tail;
} list;
这是我在 lltester.c 文件中尝试初始化列表的主要函数:
int main()
{
list myList= llinit(); //This is the line where the error occurs on!
return 0;
}