Date: Tue, 8 May 2007 16:58:37 -0400 From: John Baldwin <jhb@freebsd.org> To: Hans Petter Selasky <hselasky@c2i.net> Cc: Giorgos Keramidas <keramida@freebsd.org>, Julian Elischer <julian@elischer.org>, freebsd-arch@freebsd.org Subject: Re: Missing LIST_PREV() ? Message-ID: <200705081658.38171.jhb@freebsd.org> In-Reply-To: <200705082100.51354.hselasky@c2i.net> References: <200705051617.34162.hselasky@c2i.net> <4640C52E.7010209@elischer.org> <200705082100.51354.hselasky@c2i.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday 08 May 2007 03:00:51 pm Hans Petter Selasky wrote: > On Tuesday 08 May 2007 20:45, Julian Elischer wrote: > > John Baldwin wrote: > > > On Monday 07 May 2007 04:25:18 pm Giorgos Keramidas wrote: > > >> with other compilers. > > > > > > This can be fixed by passing the type as an argument which is what > > > TAILQ_PREV() does: > > > > > > #define TAILQ_PREV(elm, headname, field) = =20 \ > > > (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) > > > > > > I'm not sure how portable offsetof() would be though. In general if = you > > > want this feature, you should just use a TAILQ though. TAILQ_ENTRY()= is > > > the same size as a LIST_ENTRY(), it just adds one more pointer to the > > > HEAD structure. It is also specifically designed to make TAILQ_PREV() > > > work w/o needing the offsetof() hack. > > > > I agree with this.. that's why we have the different types. > > The suggested change in ingenious but I don't know how portable it is.. >=20 > I suggested the following at hacker's: >=20 > #define LIST_PREV(head,elm,field,type) \ > =A0(((elm) =3D=3D LIST_FIRST(head)) ? ((struct type *)0) : \ > =A0 ((struct type *)(((uint8_t *)((elm)->field.le_prev)) - \ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0((uint8_t *)&LIST_NEXT((struct typ= e *)0,field))))) >=20 > What do you think? Just use a TAILQ, that's what it is there for. =2D-=20 John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200705081658.38171.jhb>