question about list_for_each_entry_safe

Discussion in 'C Programming' started by gaoqiang, Oct 11, 2011.

  1. gaoqiang

    gaoqiang Guest

    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_;
    gaoqiang, Oct 11, 2011
    #1
    1. Advertising

  2. gaoqiang

    Ike Naar Guest

    On 2011-10-11, gaoqiang <> 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);
    /* ... */
    }
    Ike Naar, Oct 11, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    578
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    640
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    933
    Scott Allen
    Oct 6, 2005
  4. Philip Meyer
    Replies:
    0
    Views:
    407
    Philip Meyer
    Nov 30, 2003
  5. Bit Byte
    Replies:
    1
    Views:
    824
    Teemu Keiski
    Jan 28, 2007
Loading...

Share This Page