From owner-freebsd-arch@FreeBSD.ORG Tue May 8 19:01:12 2007 Return-Path: X-Original-To: freebsd-arch@freebsd.org Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 368F616A407 for ; Tue, 8 May 2007 19:01:12 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe10.swip.net [212.247.155.33]) by mx1.freebsd.org (Postfix) with ESMTP id 717CE13C447 for ; Tue, 8 May 2007 19:01:11 +0000 (UTC) (envelope-from hselasky@c2i.net) X-Cloudmark-Score: 0.000000 [] Received: from [193.71.38.142] (account mc467741@c2i.net HELO [192.168.1.106]) by mailfe10.swip.net (CommuniGate Pro SMTP 5.1.7) with ESMTPA id 314453130; Tue, 08 May 2007 21:01:06 +0200 From: Hans Petter Selasky To: freebsd-arch@freebsd.org Date: Tue, 8 May 2007 21:00:51 +0200 User-Agent: KMail/1.9.5 References: <200705051617.34162.hselasky@c2i.net> <200705081128.25708.jhb@freebsd.org> <4640C52E.7010209@elischer.org> In-Reply-To: <4640C52E.7010209@elischer.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200705082100.51354.hselasky@c2i.net> Cc: Julian Elischer , Giorgos Keramidas Subject: Re: Missing LIST_PREV() ? X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 May 2007 19:01:12 -0000 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) = \ > > (*(((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.. I suggested the following at hacker's: #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 type = *)0,field))))) What do you think? =2D-HPS