From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MgJoL-0008S2-HN for qemu-devel@nongnu.org; Wed, 26 Aug 2009 10:49:17 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MgJoH-0008NJ-TD for qemu-devel@nongnu.org; Wed, 26 Aug 2009 10:49:17 -0400 Received: from [199.232.76.173] (port=50278 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MgJoH-0008N2-9M for qemu-devel@nongnu.org; Wed, 26 Aug 2009 10:49:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41971) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MgJoG-0005og-LH for qemu-devel@nongnu.org; Wed, 26 Aug 2009 10:49:13 -0400 Message-ID: <4A954B61.4010708@redhat.com> Date: Wed, 26 Aug 2009 16:49:05 +0200 From: Gerd Hoffmann 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 Hi, > Why don't we declare structures like this: typedef struct { ... } T;? > I suggest this to be the new coding style for structure declarations > because it is shorter, C++ compatible and unambiguous. There are quite a few cases where this will simply not work. They usually use a slightly different declaration style though: typedef struct T T; struct T { /* stuff here */ }; Reasons why this is used/needed: (1) structs pointing to each other, like this: typedef struct A A; typedef struct B B; struct A { B *b; }; struct B { A *a; }; (2) keep the struct private, let others pass around pointers to the struct in a typesafe way though: header file: typedef struct T T; T* get_foo(args); int do_something_with_foo(T*); source file: struct T { /* stuff here */ }; cheers, Gerd