Date: Fri, 07 Nov 2008 22:07:17 +0300 From: Sergey Matveychuk <sem@FreeBSD.org> To: freebsd-hackers@freebsd.org Subject: LIST_REMOVE problem Message-ID: <491491E5.8090805@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
Hi! I wonder how this example from queue(3) works: while (!LIST_EMPTY(&head)) { /* List Deletion. */ n1 = LIST_FIRST(&head); LIST_REMOVE(n1, entries); free(n1); } If we'll take a look at code, LIST_REMOVE don't change a head pointer if you remove the first element: #define LIST_FIRST(head) ((head)->lh_first) ... #define LIST_REMOVE(elm, field) do { \ if (LIST_NEXT((elm), field) != NULL) \ LIST_NEXT((elm), field)->field.le_prev = \ (elm)->field.le_prev; \ *(elm)->field.le_prev = LIST_NEXT((elm), field); \ } while (0) So n1 in the example above will point to removed (and freed) element. -- Dixi. Sem.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?491491E5.8090805>