From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlmX6-0007ib-Lj for qemu-devel@nongnu.org; Fri, 13 Jan 2012 14:11:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RlmX4-0007A5-Lb for qemu-devel@nongnu.org; Fri, 13 Jan 2012 14:11:24 -0500 Received: from lo.gmane.org ([80.91.229.12]:42571) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlmX4-00079u-EZ for qemu-devel@nongnu.org; Fri, 13 Jan 2012 14:11:22 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RlmX1-0000Im-Ns for qemu-devel@nongnu.org; Fri, 13 Jan 2012 20:11:19 +0100 Received: from 93-34-200-238.ip51.fastwebnet.it ([93.34.200.238]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 13 Jan 2012 20:11:19 +0100 Received: from pbonzini by 93-34-200-238.ip51.fastwebnet.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 13 Jan 2012 20:11:19 +0100 From: Paolo Bonzini Date: Fri, 13 Jan 2012 20:11:04 +0100 Message-ID: References: <1326472445-25966-1-git-send-email-pbonzini@redhat.com> <1326472445-25966-4-git-send-email-pbonzini@redhat.com> <4F106457.3040208@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit In-Reply-To: <4F106457.3040208@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 3/5] qemu-queue: drop QCIRCLEQ List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org On 01/13/2012 06:05 PM, Paolo Bonzini wrote: > I think it's not entirely correct because the cast in QTAILQ_PREV and > QTAILQ_FOREACH_REVERSE does not look like valid ANSI C. No matter how > hard I look I admit I cannot figure out how it works, but anyway I > suspect it can be changed to ANSI C using typeof if one was bitten by > it. So removing QCIRCLEQ is not a bad idea anyway. Ah, got it. Here are two ways to rewrite it using typeof (not exactly ANSI C of course, but perhaps somewhat more aliasing friendly). #define QTAILQ_PREV(elm, next) \ (*(((__typeof__((elm)->next) *)((elm)->next.tqe_prev))->tqe_prev)) #define Q_TAILQ_PREV(tqe) \ ((__typeof__(tqe) *)((tqe).tqe_prev)) #define QTAILQ_PREV(elm, next) \ (Q_TAILQ_PREV(*Q_TAILQ_PREV((elm)->next))->tqe_next) It's treating the TAILQ as a half-linear (forwards), half-circular (backwards) list. Doing two backwards accesses and one forwards access ensures that the last access is always on a pointer rather than a pointer-to-pointer. Clever. Paolo