Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MfY9P-0000T7-G3 for qemu-devel@nongnu.org; Mon, 24 Aug 2009 07:55:51 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MfY9K-0000L8-Gd for qemu-devel@nongnu.org; Mon, 24 Aug 2009 07:55:50 -0400 Received: from [199.232.76.173] (port=40394 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfY9K-0000Kt-8Z for qemu-devel@nongnu.org; Mon, 24 Aug 2009 07:55:46 -0400 Received: from mx20.gnu.org ([199.232.41.8]:1083) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MfY9J-0006um-Uj for qemu-devel@nongnu.org; Mon, 24 Aug 2009 07:55:46 -0400 Received: from mail.codesourcery.com ([65.74.133.4]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MfY9I-00032v-0J for qemu-devel@nongnu.org; Mon, 24 Aug 2009 07:55:44 -0400 From: Paul Brook Subject: Re: [Qemu-devel] container_of() vs DO_UPCAST() (was: [PATCH 2/3] Clean up upcast from PCIDevice to I6300State) Date: Mon, 24 Aug 2009 12:55:13 +0100 References: <1250843494-28326-1-git-send-email-armbru@redhat.com> <87ab1pvbov.fsf_-_@pike.pond.sub.org> In-Reply-To: <87ab1pvbov.fsf_-_@pike.pond.sub.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200908241255.14045.paul@codesourcery.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster On Monday 24 August 2009, Markus Armbruster wrote: > We got container_of() in osdep.h. > > We also got DO_UPCAST() in qdev.h. Odd place, as it's not really > specific to qdev (except for the naming of the last parameter). It > takes the same parameters as container_of(), but in a different order, > which I find needlessly confusing. The last parameter is insufficiently > parenthesized in the macro expansion. Finally, I don't really like the > name --- I find container_of() much clearer --- but that's just me. > > Why do we have two macros to do essentially the same thing? > > When should container_of() be used, and when DO_UPCAST()? DO_UPCAST requires that the child object be at offset zero. Paul