Missing LIST_PREV() ?

Hans Petter Selasky hselasky at c2i.net
Sun May 6 11:57:08 UTC 2007


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


More information about the freebsd-hackers mailing list