C宏里面代码什么意思(附代码)//安全遍历#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);

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/18 03:20:11
C宏里面代码什么意思(附代码)//安全遍历#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);
xT]kA+S DCW"V@ Mji6TUW33Oޙ5Oe{=3 Lή_qLFI2Ȳt%3#ke|fh.hu>ӂ0 y̯@HqpYshDX&eMa]''2jRfk`:7YLfc2VϨY@KfFUr|Aךgysr *hbj7ZrDOZX QVӠ 1떭IʮL2WncN﷬ޢ,~f̴$I ^ i a HGs@qbTRm~*r3cV M .dn lIbv9waz6TNJkIIF?fۚLQfD {{\h O

C宏里面代码什么意思(附代码)//安全遍历#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);
C宏里面代码什么意思(附代码)
//安全遍历
#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);
}
为什么宏里面的方法重写了,

C宏里面代码什么意思(附代码)//安全遍历#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);
#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