Re: Erasing certain info from a link list.

From: Mike Stilson (mike@velgarian.sytes.net)
Date: 10/24/02


On Thu, Oct 24, 2002 at 10:31:32AM -0700, George Greer wrote:
>Maybe you want REMOVE_FROM_LIST() ??  After you've removed it from the
>list, you still have a pointer to it so you can do whatever unspeakable
>things to it you want.

Just seemed like a good time to mention this....
The problem I had long ago with REMOVE_FROM_LIST was the necessity of
remembering to define temp.

I rewrote it like this, and haven't had a problem since.  AFAIK this
isn't an extension.  (I used to use the gcc extension but, after I found
a bug which failed back to 3.0 they removed the extension of:
  typedef __type_i item;
This is their stated replacement for that extension.


#define remove_from_list(item, head) {                          \
        typedef typeof(item) __type_i;                          \
        __type_i __temp;                                        \
        if ((item) == (head)) {                                 \
                head = (item)->next;                            \
        } else {                                                \
                __temp = head;                                  \
                while (__temp && (__temp->next != (item)))      \
                        __temp = __temp->next;                  \
                if (__temp)                                     \
                        __temp->next = (item)->next;            \
        }                                                       \
}


Without this, every time you want to remove from a list, you need to
remember to define a var named 'temp'.   This does assume that the
next_in_list is "next" but that's not too hard to work around.

-me

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT