Need clarification on the content given in the Linux Kernel by Robert Love
我是LKD的新手,我正在读Robert Love的书。我坚持理解以下一个概念。
类似地,可以使用
1 2 3 4 5 6 | struct task_struct *task; struct list_head *list; list_for_each(list, ¤t->children) { task = list_entry(list, struct task_struct, sibling); /* task now points to one of current’s children */ } |
如果有人解释list_entry参数是否有效,我也很棒?
我很难理解上面的代码片段,特别是
的宏
1 2 | #define list_for_each(pos, head) \\ for (pos = (head)->next; pos != (head); pos = pos->next) |
由于C语言中的宏是通过文本替换扩展的,因此您引用的代码变成了
1 2 3 4 | for (list = (¤t->children)->next; list != (¤t->children); list = list->next) { task = list_entry(list, struct task_struct, sibling); /* task now points to one of current’s children */ } |
此代码从节点