Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 May 2007 13:56:50 +0200
From:      Hans Petter Selasky <hselasky@c2i.net>
To:        Mark Murray <mark@grondar.org>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Missing LIST_PREV() ?
Message-ID:  <200705061356.50911.hselasky@c2i.net>
In-Reply-To: <200705061139.l46BdssN017108@greatest.grondar.org>
References:  <200705061139.l46BdssN017108@greatest.grondar.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sunday 06 May 2007 13:39, Mark Murray wrote:
> Hans Petter Selasky writes:
> > Hi,
> >
> > Why should LISTs only be forward traversable? The following piece of
> > code make lists backward traversable:
>
> No objection to the concept.
>
> But...
>
> > /sys/sys/queue.h:
> >
> > +#define LIST_PREV(head,elm,field) \
> > +  (((elm) == LIST_FIRST(head)) ? ((__typeof(elm))0) : \
> > +   ((__typeof(elm))(((uint8_t *)((elm)->field.le_prev)) - \
> > +                   ((uint8_t *)&LIST_NEXT((__typeof(elm))0,field)))))
>
> Please don't use typeof; it is a GCCism. Do you really mean NULL?

Thanks for pointing that out.

Then you will have to pass an additional argument, namely the "type":

#define LIST_PREV(head,elm,field,type) \
 (((elm) == LIST_FIRST(head)) ? ((struct type *)0) : \
  ((struct type *)(((uint8_t *)((elm)->field.le_prev)) - \
                   ((uint8_t *)&LIST_NEXT((struct type *)0,field)))))

How about the order of the arguments?

Is this better?

If this is accepted I will commit it to my FreeBSD P4 USB project first. Then 
someone else can commit it to HEAD.

--HPS



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200705061356.50911.hselasky>