我試圖開發一些額外的功能https://github.com/ffnord/alfred/blob/master/vis/vis.c 因爲我不熟悉Linux列表(list.h),我試圖按照this list.h tutorial。爲此,我創建了一個非常簡單的test.c文件,並且還導入了batman/alfred提到的list.h file(通過openmesh)。list.h語法錯誤,只有當我使用我的C項目中的代碼
阿爾弗雷德/蝙蝠俠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;
}
你應該提供一個[mcve]來獲得這樣的幫助。 –
@GilHamilton done –
FWIW鏗鏘也不喜歡那條線。 'test.c:18:5:錯誤:不能取'struct list_head *''類型的右值的地址。 – Schwern