From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] Introduce QEMU_NEW() Date: Mon, 25 Jul 2011 14:35:45 +0300 Message-ID: <4E2D5511.4060002@redhat.com> References: <1311583872-362-1-git-send-email-avi@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org To: Alexander Graf Return-path: Received: from mx1.redhat.com ([209.132.183.28]:24978 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751719Ab1GYLfw (ORCPT ); Mon, 25 Jul 2011 07:35:52 -0400 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On 07/25/2011 12:32 PM, Alexander Graf wrote: > On 25.07.2011, at 10:51, Avi Kivity wrote: > > > qemu_malloc() is type-unsafe as it returns a void pointer. Introduce > > QEMU_NEW() (and QEMU_NEWZ()), which return the correct type. > > What does this buy you over > > type *x = qemu_malloc(sizeof(type)); > > ? I find the non-C++ version easier to read even. > I'm using it as MemoryRegion *phys_flash = QEMU_NEW(MemoryRegion); instead of MemoryRegion *phys_flash = qemu_malloc(sizeof(*phys_flash)); I find it shorter, and if I make a mistake, the compiler shouts at me instead of a runtime crash. -- error compiling committee.c: too many arguments to function