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: David Turner
Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
Date: Tue, 2 Jun 2009 22:42:02 +0200



On Tue, Jun 2, 2009 at 10:04 PM, Paul Brook <address@hidden> wrote:


My point is that

#define QEMU_NEW(type) ((type *)qemu_malloc(sizeof(type)))
 foo *ptr = QEMU_NEW(foo);

is just as safe as

#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]