To find out what really happens, we need a definition of struct list_head :
struct list_head { struct list_head *next, *prev; };
Now consider the macros:
#define LIST_HEAD_INIT(name) { &(name), &(name) } #define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
If in the code I write LIST_HEAD(foo) , it expands to:
struct list_head foo = { &(foo) , &(foo)}
which represents an empty doubly linked list with a node header , where the next and prev pointers point to the node header.
This is the same as doing:
struct list_head foo; foo.next = &foo; foo.prev = &foo;
Thus, these macros provide a way to initialize a doubly linked list.
And yes, & used here as the address of the operator.
EDIT:
Here is a working example
In the link provided by you. You had:
struct list_head test = LIST_HEAD (check);
which is wrong. You must have:
LIST_HEAD (check);
codaddict
source share