Missing LIST_PREV() ?
Kostik Belousov
kostikbel at gmail.com
Tue May 8 21:39:01 UTC 2007
On Tue, May 08, 2007 at 11:28:25AM -0400, John Baldwin wrote:
> On Monday 07 May 2007 04:25:18 pm Giorgos Keramidas wrote:
> > On 2007-05-07 23:20, Giorgos Keramidas <keramida at freebsd.org> wrote:
> > >On 2007-05-05 16:17, Hans Petter Selasky <hselasky at c2i.net> wrote:
> > >> 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?
> > >
> > > 1. The use of (uint8_t *) casts is relatively ugly.
>
> Looks like an ugly version of offsetof()
>
...
> I'm not sure how portable offsetof() would be though. In general if you want
offsetof() itself is defined by C standard to be present both in
freestanding and hosted environment (and be available by stddef.h).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20070508/374636a6/attachment.pgp
More information about the freebsd-arch
mailing list