Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何打印双链接列表的内容?_C_Linux_Linux Kernel - Fatal编程技术网

C 如何打印双链接列表的内容?

C 如何打印双链接列表的内容?,c,linux,linux-kernel,C,Linux,Linux Kernel,如何使用/include/linux/list.h中定义的list.h打印列表值?类似以下内容: struct list_head head; /* previously initialized */ struct list_head *pos; list_for_each(pos, head) { your_type *elt; elt = list_entry(pos, typeof(*elt), name_of_list_head_struct_member);

如何使用
/include/linux/list.h
中定义的
list.h
打印列表值?

类似以下内容:

struct list_head head; /* previously initialized */
struct list_head *pos;

list_for_each(pos, head)
{
    your_type *elt;
    elt = list_entry(pos, typeof(*elt), name_of_list_head_struct_member);
    /* and print *elt! */
}

你确定你的意思不是/usr/include/linux/list.h吗?注意:这是根据你定义
你的类型
,并将
列表头
作为它的第一个成员。这确保了
列表头
的地址与
您的类型
结构的地址相同。@torak:这是错误的,列表头成员在哪里无关紧要,您可以有多个列表头结构。其工作原理是
list\u条目
使用
container\u of
宏从结构成员获取正确的偏移量(此处
name\u of \u list\u head\u struct\u成员