Chinaunix

标题: 大家帮我看看 这两个宏有什么区别 [打印本页]

作者: liuyuanyang    时间: 2010-06-03 12:33
标题: 大家帮我看看 这两个宏有什么区别
大家帮我看看 这两个宏有什么区别
#define list_for_each(curr, head) \
        for (curr = (head)->next; curr != (head); curr = curr->next)

#define list_for_each_safe(pos, tmp, head) \
        for (pos = (head)->next, tmp = pos->next; pos != (head); \
                pos = tmp, tmp = pos->next)
作者: ShadowStar    时间: 2010-06-03 13:07
一个safe,一个不safe{:3_180:}
作者: openspace    时间: 2010-06-03 13:51
搜了一篇
http://blog.chinaunix.net/u3/102267/showart_2210383.html
作者: platinum    时间: 2010-06-03 13:56
后者可以在处理循环中删除这个节点,而前者不行
作者: Godbach    时间: 2010-06-03 15:13
白金兄说得对。一个仅用于读,加safe的那个可以用于删除节点。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2