From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MgKq5-00031U-Ed for qemu-devel@nongnu.org; Wed, 26 Aug 2009 11:55:09 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MgKq0-0002xf-Ti for qemu-devel@nongnu.org; Wed, 26 Aug 2009 11:55:09 -0400 Received: from [199.232.76.173] (port=37112 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MgKq0-0002xR-GX for qemu-devel@nongnu.org; Wed, 26 Aug 2009 11:55:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61914) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MgKq0-0000Ww-1K for qemu-devel@nongnu.org; Wed, 26 Aug 2009 11:55:04 -0400 Message-ID: <4A955AD2.8000500@redhat.com> Date: Wed, 26 Aug 2009 18:54:58 +0300 From: Avi Kivity MIME-Version: 1.0 Subject: Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense) References: <51486eb6860d1680c1bce45e310dcd3aae096f43.1251111439.git.quintela@redhat.com> <4A928DF0.9000106@weilnetz.de> <87tyzxnwvb.fsf@pike.pond.sub.org> <4A953E20.8080806@mail.berlios.de> In-Reply-To: <4A953E20.8080806@mail.berlios.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil Cc: Anthony Liguori , Markus Armbruster , qemu-devel@nongnu.org On 08/26/2009 04:52 PM, Stefan Weil wrote: >>> I wrote these type casts, and I think they make sense. >>> In C++ code, they are even mandatory. >>> >> Yes, but this isn't C++. >> >> >>> I think the arguments why C++ requires this kind of >>> type casts apply to C code (like in Qemu) as well. >>> >>> If it is possible with no or very litte efforts to write >>> code which is C and C++ compatible, I prefer to do so. >>> >> I respectfully disagree. Casts from "void *" to "T *" are pure noise. >> Getting into the habit of writing noise casts runs the risk of silencing >> warnings that flag real type errors. >> > Hello > > Do you only disagree with my first sentence or with both sentences? > > Currently, I seem to be alone with my opinion (at least in qemu-devel). > You are not alone. > Nevertheless, the designers of C++ thought that casts from void * to > T * were something very important. I don't know the history of their > decision. 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. > Yes. > Let me give one more C/C++ example. Today, many data structures > are declared like this: typedef struct T { ... } T; > There is nothing wrong with it, but it can be improved in > several ways: > > * The declaration does not work with C++ (yes, I know that many > programmers are not interested in C++ compatibility for QEMU). > It does work in C++. > * The declaration allows variable declarations using struct T var; > or just T var; (which is the QEMU style). I think a declaration > which does not enforce the correct style is less good. > It's often needed, for example to have a struct T * in T. -- error compiling committee.c: too many arguments to function