Missing LIST_PREV() ?
Hi, Why should LISTs only be forward traversable? The following piece of code make lists backward traversable: /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) Any comments? --HPS ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Missing LIST_PREV() ?
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? M -- Mark R V Murray - Cert APS(Open) Dip Phys(Open) BSc Open(Open) ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Missing LIST_PREV() ?
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 ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]