Received: from [140.186.70.92] (port=40705 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PsVKl-00038x-SR for qemu-devel@nongnu.org; Thu, 24 Feb 2011 02:09:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PsVKk-0007oh-KI for qemu-devel@nongnu.org; Thu, 24 Feb 2011 02:09:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34937) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PsVKk-0007ob-9m for qemu-devel@nongnu.org; Thu, 24 Feb 2011 02:09:54 -0500 From: Markus Armbruster Subject: Re: [Qemu-devel] Re: [PATCH 16/28] migration: use global variable directly References: <8b675b6ffee29ec15f2b73a9fd47e334429f5c5c.1298492768.git.quintela@redhat.com> <4D6587C7.6030604@codemonkey.ws> <4D659295.1070400@codemonkey.ws> Date: Thu, 24 Feb 2011 08:09:50 +0100 In-Reply-To: <4D659295.1070400@codemonkey.ws> (Anthony Liguori's message of "Wed, 23 Feb 2011 17:04:53 -0600") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org, quintela@redhat.com Anthony Liguori writes: > On 02/23/2011 04:46 PM, Juan Quintela wrote: >> Anthony Liguori wrote: >> >>> On 02/23/2011 03:47 PM, Juan Quintela wrote: >>> >>>> We are setting a pointer to a local variable in the previous line, just use >>>> the global variable directly. We remove the ->file test because it is already >>>> done inside qemu_file_set_rate_limit() function. >>>> >>>> >>> I think this is bad form generally speaking. Globals are not >>> something to be embraced but rather to be isolated as much as humanly >>> possible. >>> >> current_migration is a global variable. >> >> And just doing: >> >> s = current_migration; >> >> foo(s); >> >> helps nothing. > > It's still bad form IMHO. You should always use local variables to > reference global variables unless you're explicitly setting a global > variable. I disagree. The use of global variables should be made as painfully explicit as possible. Hiding them behind local pointers is sweeping the globals under the rug. For completeness: a local variable may be necessary to convince the optimizer that the value doesn't change. Cases where this matters exist, but they're rare.