【发布时间】:2013-06-05 14:33:40
【问题描述】:
我在 Linux (include/linux/list.h) 中遇到了以下代码。我对第 713 行感到困惑。特别是,我不明白 ({ n = pos->member.next; 1; })。
花括号在做什么?为什么这个语句中有一个“1”?
如果有人能解释这一特定行,将不胜感激。请注意,我不需要解释链接列表和#defines 的工作原理等。
704 /**
705 * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
706 * @pos: the type * to use as a loop cursor.
707 * @n: another &struct hlist_node to use as temporary storage
708 * @head: the head for your list.
709 * @member: the name of the hlist_node within the struct.
710 */
711 #define hlist_for_each_entry_safe(pos, n, head, member) \
712 for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
713 pos && ({ n = pos->member.next; 1; }); \
714 pos = hlist_entry_safe(n, typeof(*pos), member))
715
【问题讨论】:
-
({ /* code */ })是一个 GNU 扩展,一个语句表达式。大括号内的代码被执行,其值为里面最后一个表达式的值。
标签: c linux linked-list curly-braces