#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