qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently


From: Gerd Hoffmann
Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
Date: Tue, 02 Jun 2009 22:45:52 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Lightning/1.0pre Thunderbird/3.0b2

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







reply via email to

[Prev in Thread] Current Thread [Next in Thread]