From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MBau2-0005GI-Ou for qemu-devel@nongnu.org; Tue, 02 Jun 2009 16:48:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MBaty-0005Ax-0V for qemu-devel@nongnu.org; Tue, 02 Jun 2009 16:48:10 -0400 Received: from [199.232.76.173] (port=58565 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBatx-0005Ao-PK for qemu-devel@nongnu.org; Tue, 02 Jun 2009 16:48:05 -0400 Received: from mx2.redhat.com ([66.187.237.31]:34577) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MBatx-0001xM-1j for qemu-devel@nongnu.org; Tue, 02 Jun 2009 16:48:05 -0400 Message-ID: <4A258F80.6090605@redhat.com> Date: Tue, 02 Jun 2009 22:45:52 +0200 From: Gerd Hoffmann MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently References: <200905290758.11551.jcd@tribudubois.net> <200906021913.09517.paul@codesourcery.com> <60cad3f0906021249t435fc1a8w4f89027e0863ff52@mail.gmail.com> <200906022104.55121.paul@codesourcery.com> <60cad3f0906021342s36cdbd52r6056ed552ba1ae82@mail.gmail.com> In-Reply-To: <60cad3f0906021342s36cdbd52r6056ed552ba1ae82@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Turner Cc: Kevin Wolf , Jean-Christophe Dubois , Paul Brook , qemu-devel@nongnu.org On 06/02/09 22:42, David Turner wrote: >> #define QEMU_NEW(type) ((type *)qemu_malloc(sizeof(type))) >> #define QEMU_NEW(ptr) (ptr) = qemu_malloc(sizeof(*(ptr))) >> foo *ptr; >> QEMU_NEW(ptr); >> >> Because the compiler will catch the type mismatch. >> > > I still don't see the point. > There is no type mismatch in the first version since the C standard mandates > that a (void*) *must* be silently casted into any other typed pointer > (unlike C++ which forbids this). > > I think you're afraid of the following case instead: > > foo* ptr; > ptr = QEMU_MEW(bar); => compiler will complain that 'ptr' is not a bar* > > But this is not possible with the first version anyway. > > > >> Paul >> >