Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

link list implementation in linux kernel easy question syntax not clear


  • Please log in to reply
No replies to this topic

#1 onus


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 113 posts

Posted 08 October 2010 - 10:31 PM

Hi,in Linux Kernel
following section of code
there is a structure which is defined as
struct list_head {
        struct list_head *next, *prev;
It is used in another file as
#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name) \
        struct list_head name = LIST_HEAD_INIT(name)

static inline void INIT_LIST_HEAD(struct list_head *list)
        list->next = list;
        list->prev = list;

I came across a book where the code is given as follows in an example
struct list_head {
struct list_head *next,*prev;
#define LIST_HEAD_INIT(name) {&(name),&(name)}

#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr) do {\
(ptr)->next = (ptr);(ptr)->prev= (ptr);\

I was not able to understand above code segment.
I am aware of what a #define is but still I could not understand above thing.
Can some one help in understanding with some example.
Not related to Linux Kernel a normal example where I can make a link list with above defined way.
  • 0

Also tagged with one or more of these keywords: syntax

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download