A newer REMOVE_FROM_LIST()

From: Daniel Koepke (dkoepke@california.com)
Date: 01/04/97


As someone who loves to use linked lists (heh), I personally got
a bit aggitated at needing the 'temp' variable.  So, I set out
for a way to have REMOVE_FROM_LIST() completely self-contained
without relying on C++.  And wouldn't you know?  I found a method
using a GCC extension of 'typedef' [that I managed to discover
with faulty code]...

Now, I've not tested the below extensively, although it seems to work
fine for me.  Let's see if I don't mess it up:

  #define RemoveFromList(item, list, next)				\
    ({typedef _tl = (list);						\
      _tl _tlrf;							\
      if ((item) == (list))						\
        list = (item)->next;						\
      else {								\
        _tlrf = (list);							\
        while (_tlrf && (_tlrf->next != (item)))			\
          _tlrf = _tlrf->next;						\
        if (_tlrf)							\
	  _tlrf->next = (item)->next;					\
      }})

Now, the reasoning behind using "_tlrf" as the variable name, which
is a rather annoying name, is because there's a low likelihood you
have any variable with that name used within any of your functions.
Since '_tlrf' is defined within the function as the same type as the
list, we no longer need 'temp' to be defined.  Installing this code,
provided it compiles for you, in place of REMOVE_FROM_LIST() should
not cause any compatibility problems with existing code.  Most likely
you'll see 'unused variable' warnings for "temp" around the place,
but those are easy enough to change or ignore.

Your thoughts?


--
Daniel Koepke
dkoepke@california.com
Forgive me father, for I am sin.


+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/18/00 PST