我正在尝试开发https://github.com/ffnord/alfred/blob/master/vis/vis.c的一些额外功能 由于我不熟悉Linux列表(list.h),我试图关注this list.h tutorial。为此,我创建了一个非常简单的test.c文件,我还导入了提到的list.h file batman / alfred(由openmesh提供)。
Alfred / batman Github代码编译完美无缺,但在示例代码中GCC抱怨list.h。
Description Resource Path Location Type
expected ‘;’ before ‘}’ token list.h /C_Linux_kernel_lists/src line 68 C/C++ Problem
Description Resource Path Location Type
lvalue required as unary ‘&’ operand list.h /C_Linux_kernel_lists/src line 68 C/C++ Problem
所以我的问题是:为什么GCC不会抱怨上游list.h代码,当我尝试使用相同的代码时它会返回那些消息?
附加源代码:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "list.h"
struct Person
{
char name[30];
unsigned int weight;
unsigned char gender;
struct list_head list;
};
int main()
{
struct Person personList;
LIST_HEAD_INIT(&personList.list);
struct Person* aNewPersonPointer;
aNewPersonPointer = malloc(sizeof(*aNewPersonPointer));
strcpt(aNewPersonPointer->name, "roman10");
aNewPersonPointer->weight = 130;
aNewPersonPointer->gender = 1;
INIT_LIST_HEAD(&aNewPersonPointer->list);
list_add(&aNewPersonPointer->list, &personList.list);
return 0;
}
答案 0 :(得分:2)
我相信你应该致电INIT_LIST_HEAD
而不是LIST_HEAD_INIT
。这只是基于alfred代码的其余部分如何使用列表界面的猜测,LIST_HEAD_INIT
从未在list.h之外使用,但INIT_LIST_HEAD
在main.c
中,{{1 }和recv.c
。