Reputation: 2642
I am trying to develop some extra functionalities of https://github.com/ffnord/alfred/blob/master/vis/vis.c Since that I am not familiar with Linux lists (list.h), I tried to follow this list.h tutorial. To do that I created a very simple test.c file and I imported also the mentioned list.h file of batman/alfred (by openmesh).
Alfred/batman Github code compiles flawlessly, but in the example code GCC complains about 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
So my question is: why GCC does not complain with upstream list.h code and it returns me those messages when I try to use the same code?
Attached source code:
#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;
}
Upvotes: 4
Views: 286
Reputation: 165175
I believe you should be calling INIT_LIST_HEAD
and not LIST_HEAD_INIT
. This is just a guess based on how the rest of the alfred code uses the list interface, LIST_HEAD_INIT
is never used outside of list.h, but INIT_LIST_HEAD
is in main.c
, recv.c
and vis/vis.c
.
This is pointed out in a comment on that tutorial.
Upvotes: 2