Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > question about list_for_each_entry_safe

Reply
Thread Tools

question about list_for_each_entry_safe

 
 
gaoqiang
Guest
Posts: n/a
 
      10-11-2011
in linux kernel,there is such code that:
213 /**
214 * list_for_each_entry_safe - iterate over list of given type safe
against removal of list entry
215 * @pos: the type * to use as a loop cursor.
216 * @n: another type * to use as temporary storage
217 * @head: the head for your list.
218 * @member: the name of the list_struct within the struct.
219 */
220 #define list_for_each_entry_safe(pos, n, head, member) \
221 for (pos = list_entry((head)->next, typeof(*pos), member), \
222 n = list_entry(pos->member.next, typeof(*pos), member); \
223 &pos->member != (head); \
224 pos = n, n = list_entry(n->member.next, typeof(*n),
member))


why an additional param "n" should passed in?

I think the following code will work fun....

#define list_for_each_entry_safe(pos, head, member) \
--->> typeof(*pos) *_tmp_n_;
 
Reply With Quote
 
 
 
 
Ike Naar
Guest
Posts: n/a
 
      10-11-2011
On 2011-10-11, gaoqiang <(E-Mail Removed)> wrote:
> in linux kernel,there is such code that:
> 213 /**
> 214 * list_for_each_entry_safe - iterate over list of given type safe
> against removal of list entry
> 215 * @pos: the type * to use as a loop cursor.
> 216 * @n: another type * to use as temporary storage
> 217 * @head: the head for your list.
> 218 * @member: the name of the list_struct within the struct.
> 219 */
> 220 #define list_for_each_entry_safe(pos, n, head, member) \
> 221 for (pos = list_entry((head)->next, typeof(*pos), member), \
> 222 n = list_entry(pos->member.next, typeof(*pos), member); \
> 223 &pos->member != (head); \
> 224 pos = n, n = list_entry(n->member.next, typeof(*n),
> member))
>
>
> why an additional param "n" should passed in?
>
> I think the following code will work fun....
>
> #define list_for_each_entry_safe(pos, head, member) \
> --->> typeof(*pos) *_tmp_n_;


Then the macro would break silently when called with an argument
with that name, e.g.

{
/* declaration of _tmp_n_ */
/* ... */
list_for_each_entry_safe(_tmp_n_, some_head, some_member);
/* ... */
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments