From owner-freebsd-hackers@FreeBSD.ORG Sun May 6 11:57:08 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AC8C816A402 for ; Sun, 6 May 2007 11:57:08 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe07.swip.net [212.247.154.193]) by mx1.freebsd.org (Postfix) with ESMTP id 49A1013C44B for ; Sun, 6 May 2007 11:57:08 +0000 (UTC) (envelope-from hselasky@c2i.net) X-Cloudmark-Score: 0.000000 [] Received: from [81.191.58.152] (account mc467741@c2i.net HELO laptop.lan) by mailfe07.swip.net (CommuniGate Pro SMTP 5.1.7) with ESMTPA id 483141486; Sun, 06 May 2007 13:57:06 +0200 From: Hans Petter Selasky To: Mark Murray Date: Sun, 6 May 2007 13:56:50 +0200 User-Agent: KMail/1.9.5 References: <200705061139.l46BdssN017108@greatest.grondar.org> In-Reply-To: <200705061139.l46BdssN017108@greatest.grondar.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200705061356.50911.hselasky@c2i.net> Cc: freebsd-hackers@freebsd.org Subject: Re: Missing LIST_PREV() ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 May 2007 11:57:08 -0000 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