qemu-devel
[Top][All Lists]
Advanced

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

Re: Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22


From: Reimar Döffinger
Subject: Re: Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense)
Date: Wed, 26 Aug 2009 17:58:24 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

On Wed, Aug 26, 2009 at 04:20:14PM +0100, Måns Rullgård wrote:
> Stefan Weil <address@hidden> writes:
> > I personally think that deriving a data type T from some bytes in
> > memory which can contain anything is an operation which is worth
> > being documented by the programmer, and this is exactly what the
> > cast does.
> 
> The declaration and assignment already make that perfectly clear.  The
> cast is at best noise, and often hides a real error.

There are additional points, having all those casts makes people used to
them and generally makes it much harder to spot those that are just
wrong (not that C++ does not have this issue, since basically all
conversions/uses of void* are wrong, with C they are unavoidable).
Having casts for malloc results also makes it needlessly hard to change
the type. Use
var = malloc(count * sizeof(*var))
and you only need to change the declaration, add a cast and you also
have to change all places where such allocations are done.




reply via email to

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