On Tue, Jun 2, 2009 at 8:13 PM, Paul Brook
<address@hidden> wrote:
> > QEMU_NEW_ARRAY(ptr, ...);
> >
> > instead of
> >
> > ptr = QEMU_NEW_ARRAY(...);
> >
> > then. I don't see another easy way to get the automagic sizeof(*ptr)
> > stuff done though.
>
> The first version will extract the item size automatically for you, making
> it less likely that you screw things in the second version's parameter
> list.
Not if you do it properly it won't.
If you do it properly, then bugs do not exist, and this thread has no reason to exist.
We're talking about it precisely because we're human and people tend to make mistakes.
Implicit casts are only silently allowed
between void* and arbitrary pointers. A cast between two arbitrary pointers
will generate a compiler diagnostic.
Ok, let's say that the first one should only be used when 'ptr' is a typed pointer so that
sizeof(*(ptr)) has a sense. I think it catches 95% of uses here.
Very frankly I don't see your point. Either you want to reduce the probability of programming
errors, and find ways to achieve that, or you don't. I just don't think that introducing an abort()
on qemu_malloc(0) makes sense because it goes against the principle of least surprise, especially
for a lot of programmers that already do things properly.
Paul