On Tue, 6 Jul 2004, Philip Reynolds wrote:
> You need to use a temporary variable, to allow the use of free() or
> removal of an element in the list.
Indeed. the problem is trying to stuff it into the for loop so that
macro will still work :)
> #define LIST_LOOP(L, V, N, temp) \
> for ((N) = (L)->head; \
> (N) && ((temp) = (N)->next); \
> (N) = (temp))
>> Something like the above.
Nah, that breaks the macro.
However, I've had very useful suggestions from messrs Lyda and
Arlied, which I've to go test out. Something like:
#define LIST_LOOP (list, val, this, next) \
for ( (this) = (list)->head, (next) = (this)->next; \
(this) != NULL; \
(next) = (this)->next, (this) = (next)) \
if ( ((val) = (this)->data) != NULL)
Should do the trick (as discerned from the linux kernel list macros,
which dave pointed me at, so damn obvious once you see it of course).
Lyda actually managed to shove conditionals into the for loop, but in
his defence, because I had insisted that i needed assignment of next
to be conditional, so it's not his fault ;). I havnt tested whether
it's portable yet though (it has to work with a certain compiler
which is a bit stricter than gcc).
> --
> Philip Reynolds | RFC Networks Ltd.
regards,
--
Paul Jakma paul at clubi.iepaul at jakma.org Key ID: 64A2FF6A
warning: do not ever send email to spam at dishone.st
Fortune:
panic: kernel segmentation violation. core dumped (only kidding)
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!