日期:2014-05-16  浏览次数:20632 次

链表问题
hlist_for_each_entry(tpos, pos, head, member) \
  for (pos = (head)->first; \
  pos && ({ prefetch(pos->next); 1;}) && \
  ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  pos = pos->next)
prefetch(pos->next);1; 加;1;是干什么?哪位高手知道?

------解决方案--------------------
pos && ({ prefetch(pos->next); 1;}) && \
可能是想让两个&&之间的值为1吧。
------解决方案--------------------
int main()
{
printf("%d\n", ({0; 1;}));
printf("%d\n", ({1; 0;}));
}

------解决方案--------------------
for (pos = (head)->first; xxxx ; pos = pos->next)
中间判断循环结束条件那一大串,分开来看就是:
如果pos为NULL就结束循环,否则执行prefetch和hlist_entry
加上两个;1; 是为了忽略掉prefetch和hlist_entry的返回值,使pos成为判断循环结束的唯一条件。

a && b; 如果表达式a的结果是0,就不会执行表达式b
所以,当pos为NULL, prefetch和hlist_entry不会执行。