From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StJFE-0000Fj-BM for qemu-devel@nongnu.org; Mon, 23 Jul 2012 10:04:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StJFC-0008V3-Ig for qemu-devel@nongnu.org; Mon, 23 Jul 2012 10:04:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5497) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StJFC-0008Ux-AD for qemu-devel@nongnu.org; Mon, 23 Jul 2012 10:04:18 -0400 Message-ID: <500D5A23.205@redhat.com> Date: Mon, 23 Jul 2012 16:05:23 +0200 From: Laszlo Ersek 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> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: Paolo Bonzini , Zhi Yong Wu , Stefan Hajnoczi , Zhi Yong Wu , qemu-devel@nongnu.org On 07/23/12 15:49, Stefan Hajnoczi wrote: > On Mon, Jul 23, 2012 at 1:45 PM, Laszlo Ersek wrote: >> Two hairs to split: >> >> On 07/20/12 14:01, Stefan Hajnoczi wrote: >> >>> +static NetHubPort *net_hub_port_new(NetHub *hub, const char *name) >>> +{ >>> + VLANClientState *nc; >>> + NetHubPort *port; >>> + unsigned int id = hub->num_ports++; >> >> There are projects that don't like to put logic or externally visible >> side-effects into initializers. I don't know about qemu. > > I see what you're saying, we also add it to the hub's port list > further down. It could be split into _new() and hub_add_port(hub, > port) but then autogenerating a unique name becomes harder. Since > this function is static, the scope is limited and we can assume > callers understand what is going on here. > > I'd like to leave it this way or do you see a concrete change that > improves the code? Oh no, that's not what I meant -- the function is perfectly fine, it's just that the post-increment of object A shouldn't be in the definition / initializer list of object B. (Keeping the increment and the construcion in one place is actually a good thing IMHO.) The idea is, rather than unsigned int id = hub->num_ports++; it should say unsigned int id; /* ... */ id = hub->num_ports++; ... Hm, yes, I remember it from . But again, I'm not sure how qemu treats this. Laszlo