[Top][All Lists]
[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.
- [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), (continued)
- [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), Stefan Weil, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), Gerd Hoffmann, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), Jamie Lokier, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), malc, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), Jamie Lokier, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), malc, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), Jamie Lokier, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code, Markus Armbruster, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code, Anthony Liguori, 2009/08/26
- Re: Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), Måns Rullgård, 2009/08/26
- Re: Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense),
Reimar Döffinger <=
- Re: Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), Avi Kivity, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), Avi Kivity, 2009/08/26
- Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense), Jamie Lokier, 2009/08/26
- Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense, Gerd Hoffmann, 2009/08/24
[Qemu-devel] [PATCH 01/22] eepro100: convert casts to DO_UPCAST(), Juan Quintela, 2009/08/24
[Qemu-devel] [PATCH 03/22] eepro100: Remove unused indirection of PCIDevice, Juan Quintela, 2009/08/24
[Qemu-devel] [PATCH 04/22] es1370: Remove unused indirection of PCIES1370State and ES1370State, Juan Quintela, 2009/08/24
[Qemu-devel] [PATCH 07/22] ne2000: Remove unneeded double indirection of PCINE2000State, Juan Quintela, 2009/08/24