C宏里面代码什么意思(附代码)//安全遍历#define list_for_each_safe(cur,tmp,list

1个回答

  • #define list_for_each_safe(cur, tmp, list)

    for (cur = (list)->head.next,

    tmp = (cur)->next;

    cur != &(list)->head;

    cur = tmp, tmp = (tmp)->next)

    上面这些是宏代码,

    下面这些是调用这个宏.

    list_for_each_safe(cur, tmp, dlist) {

    dlist->del(cur);

    }

    再说说宏代码吧:

    是个连接符,由于宏定义基本是在同一行的,但是有些代码比较长,在同一行定义看起来很别扭,所以加了个 就可以换行了,所以 相当于换行符.

    这个 list_for_each_safe(cur, tmp, list) 看起来像个函数吧,你也可以看成函数,差不多意思.

    for (cur = (list)->head.next,

    tmp = (cur)->next;

    cur != &(list)->head;

    cur = tmp, tmp = (tmp)->next)

    上面这一堆就是个for循环的条件表达式,类似于 for(i=0;i