What does it means?

J

jebaanandhan

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


Thanks
Jeba
 
M

Mark Bluemel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top