From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StLZw-0004Cw-KD for qemu-devel@nongnu.org; Mon, 23 Jul 2012 12:33:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StLZv-00051M-CG for qemu-devel@nongnu.org; Mon, 23 Jul 2012 12:33:52 -0400 Received: from cantor2.suse.de ([195.135.220.15]:40225 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StLZv-000516-26 for qemu-devel@nongnu.org; Mon, 23 Jul 2012 12:33:51 -0400 Message-ID: <500D7CE7.9040903@suse.de> Date: Mon, 23 Jul 2012 18:33:43 +0200 From: =?ISO-8859-1?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1342785709-3152-1-git-send-email-stefanha@linux.vnet.ibm.com> <1342785709-3152-2-git-send-email-stefanha@linux.vnet.ibm.com> <500D4754.2020301@redhat.com> <500D5A23.205@redhat.com> <500D6AB0.1050703@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 01/16] net: Add a hub net client List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Stefan Hajnoczi , Erik Blake , qemu-devel@nongnu.org, Zhi Yong Wu , Blue Swirl , Zhi Yong Wu , Paolo Bonzini , Laszlo Ersek Am 23.07.2012 17:23, schrieb Stefan Hajnoczi: > On Mon, Jul 23, 2012 at 4:16 PM, Laszlo Ersek wrote= : >> On 07/23/12 16:52, Stefan Hajnoczi wrote: >>> On Mon, Jul 23, 2012 at 3:05 PM, Laszlo Ersek wro= te: >> >>>> The idea is, rather than >>>> >>>> unsigned int id =3D hub->num_ports++; >>>> >>>> it should say >>>> >>>> unsigned int id; >>>> /* ... */ >>>> id =3D hub->num_ports++; >>> >>> "Be careful to not obfuscate the code by initializing variables in th= e >>> declarations. Use this feature only thoughtfully. DO NOT use >>> function calls in initializers." >>> >>> This? >>> >>> Do you know the rationale? It's not clear to me how this "obfuscates= " the code. >> >> I think the rationale is that (a) people tend to reorganize definition= s, >> and the expressions in the initializer lists may depend on the origina= l >> order, (b) even worse with removal of variables, (c) many people have = a >> "conceptual divide" between the definition block and the logic below i= t, >> and the first should set constant defaults at most. (Naturally this >> prevents C99/C++ style mixing of definitions and code as well, at leas= t >> without explicit braces.) >> >> I'm one of those people, but again I'm not sure if qemu has any >> guideline on this. >> >> >>> Messing around with side-effects in a series of variable declarations >>> with intializers could be bug-prone. But here there is only one >>> initializer so it's not a problem. >>> >>> Regarding QEMU, there's no coding style rule against initializers. >>> Personally I think that's a good thing because it keeps the code >>> concise - people reading it don't have to keep the declaration in >>> their mind until they hit the initializer later on. >> >> Well I keep the definitions at the top of the block so I can very easi= ly >> return to them visually (and be sure they do nothing else than define >> variables / declare externs), but it's getting philosophical :) >> >> I have nothing against this initializer as-is, I just wanted to voice >> *if* there's such a guideline in qemu *then* it should be followed :) >=20 > Yes, I understand - it's a question of style or flamewar fodder :). I > double-checked that there is no guideline in ./CODING_STYLE and > ./HACKING. Hm, I'm not so much into those documents [cc'ing Blue], but we used to be stricter about ANSI C some years back (which iirc forbids non-constant expressions in initializers?). FWIW we have since switched to C99 struct initializers and use QOM cast macros (that translate to a function call) in initializers. -ansi -pedantic is unlikely to get far. Cheers, Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg