What does it means?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jebaanandhan@gmail.com

    #1

    What does it means?

    Hi all,
    i have come across the following snippets of code in linux kernel. It
    would be grateful if somebody clarifies me what does the following
    code means.



    Code: reference : include/linux/list.h

    #define LIST_HEAD_INIT( name) { &(name), &(name) }

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


    the exact replacement will be
    >listhead name = { &(name), &(name)};


    Thanks
    Jeba
  • Mark Bluemel

    #2
    Re: What does it means?

    jebaanandhan@gm ail.com wrote:
    Hi all,
    i have come across the following snippets of code in linux kernel. It
    would be grateful if somebody clarifies me what does the following
    code means.
    >
    >
    >
    Code: reference : include/linux/list.h
    >
    #define LIST_HEAD_INIT( name) { &(name), &(name) }
    >
    #define LIST_HEAD(name) \
    struct list_head name = LIST_HEAD_INIT( name)
    I have a feeling we've discussed this before, and I think a bit
    of Googling could find you some discussion both in this group
    and in the linux mailing lists - the latter would probably be
    a more useful source of answers to questions about the rationale
    for this design...

    I presume, and half-remember, that struct list_head holds
    pointers to a doubly-linked, perhaps circular, list.

    The starting position for such a list would be a node which
    which pointed to itself. That's what LIST_HEAD_INIT produces.

    As I half-recall, the code uses this list structure for lots of
    lists, so plays games something like this :-

    struct list_head {
    struct list_head *next;
    struct list_head *prev;
    };

    struct potential_head_ coaches {
    struct list_head head;
    char *name;
    };

    LIST_HEAD(coach _list);

    struct teams_that_can_ beat_us {
    struct list_head head;
    char *country;
    };

    LIST_HEAD(good_ teams);

    And casts "coach_list " and "good teams" as appropriate.

    Comment

    Working...