On Mon, 20 Oct 1997, Daniel Koepke wrote: > -+/* BEGIN REMOVE_FROM_LIST */ This is not quite related to this, but just some minor, maybe useful thing: for removing things from linked lists I use this macro (having gotten tired after writing the same code for the Nth time :) e.g. UNLINK(ch, char_list); LINK(something, something_list); Note thaty they are gcc specific (typeof() gcc extension). #define UNLINK(item, list_head) do \ { \ if ((item) == (list_head)) \ (list_head) = (item)->next; \ else \ { \ typeof(item) tmp; \ for (tmp = (list_head); tmp; tmp = tmp->next) \ if (tmp->next == (item)) \ break; \ if (!tmp) \ bug ("UNLINK: did not find previous item: " __FILE__ ":%d" ,__LINE__); \ else \ tmp->next = (item)->next; \ } } while(0) This might also be useful: /* Link an item into a linked list (at the end of it)*/ #define LINK(item, list_head) do \ { \ if ((list_head) == NULL) \ list_head = item; \ else \ { \ typeof(item) prev; \ for (prev = (list_head); prev && prev->next; prev = prev->next); \ prev->next = item; \ } \ } while(0) ============================================================================= Erwin Andreasen Herlev, Denmark <erwin@pip.dknet.dk> UNIX System Programmer <URL:http://pip.dknet.dk/~erwin/> <*> (not speaking for) DDE ============================================================================= +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST