From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MgKtS-0005c1-V4 for qemu-devel@nongnu.org; Wed, 26 Aug 2009 11:58:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MgKtO-0005Yt-H9 for qemu-devel@nongnu.org; Wed, 26 Aug 2009 11:58:38 -0400 Received: from [199.232.76.173] (port=42083 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MgKtO-0005Yl-3O for qemu-devel@nongnu.org; Wed, 26 Aug 2009 11:58:34 -0400 Received: from mail.gmx.net ([213.165.64.20]:53319) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MgKtN-00018l-Ep for qemu-devel@nongnu.org; Wed, 26 Aug 2009 11:58:33 -0400 Date: Wed, 26 Aug 2009 17:58:24 +0200 From: Reimar =?iso-8859-1?Q?D=F6ffinger?= Subject: Re: Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense) Message-ID: <20090826155824.GA3785@1und1.de> References: <51486eb6860d1680c1bce45e310dcd3aae096f43.1251111439.git.quintela@redhat.com> <4A928DF0.9000106@weilnetz.de> <87tyzxnwvb.fsf@pike.pond.sub.org> <4A953E20.8080806@mail.berlios.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org On Wed, Aug 26, 2009 at 04:20:14PM +0100, Måns Rullgård wrote: > Stefan Weil 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.