From owner-freebsd-arch@FreeBSD.ORG Tue Feb 1 21:23:07 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 112E016A4CE for ; Tue, 1 Feb 2005 21:23:07 +0000 (GMT) Received: from ns1.xcllnt.net (209-128-86-226.BAYAREA.NET [209.128.86.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6BF8643D5A for ; Tue, 1 Feb 2005 21:23:06 +0000 (GMT) (envelope-from marcel@xcllnt.net) Received: from [192.168.4.250] (dhcp50.pn.xcllnt.net [192.168.4.250]) by ns1.xcllnt.net (8.13.1/8.13.1) with ESMTP id j11LN5HI012570; Tue, 1 Feb 2005 13:23:05 -0800 (PST) (envelope-from marcel@xcllnt.net) In-Reply-To: <20050201204331.GH61409@myrddin.originative.co.uk> References: <20050128173327.GI61409@myrddin.originative.co.uk> <20050131102630.GJ61409@myrddin.originative.co.uk> <20050201180624.GB19624@funkthat.com> <20050201190416.GG61409@myrddin.originative.co.uk> <20050201204331.GH61409@myrddin.originative.co.uk> Mime-Version: 1.0 (Apple Message framework v619.2) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <7133afbc3492c934b5686c5e6f0911b1@xcllnt.net> Content-Transfer-Encoding: 7bit From: Marcel Moolenaar Date: Tue, 1 Feb 2005 13:23:04 -0800 To: Paul Richards X-Mailer: Apple Mail (2.619.2) cc: arch@freebsd.org Subject: Re: c99/c++ localised variable definition X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 21:23:07 -0000 On Feb 1, 2005, at 12:43 PM, Paul Richards wrote: > On Tue, Feb 01, 2005 at 12:30:37PM -0800, Marcel Moolenaar wrote: >> On Feb 1, 2005, at 11:04 AM, Paul Richards wrote: >> >>>> And wonder why i gets such a strange value... It appears that >>>> unless >>>> you have WARNS=4 set, warnings about: >>>> t.c:10: warning: declaration of 'i' shadows a previous local >>>> >>>> don't show up. So, I would say we HAVE to get the tree building >>>> with >>>> WARNS=4 and -Werror before we let this into style(9)... >>> >>> The issue with shadowing outer scope variables is only an issue if >>> you need to access them. If your only using the syntax for loop >>> variables to do the looping then there's no issue. >> >> Never forget that you want to be able to debug you application. >> While technically you're right, it's bad practice to do so. > > I disagree with this point. I think it's more error prone to rely on a > side effect of a loop variable to exist outside the scope of the loop. There's no side-effect. You define it outside the loop. You know that the scope will be larger than the scope of the loop itself. The only down side is that the life-range spans the whole function and not the one loop it is used in. *cases snipped* It's all subjective and very much dependent on the context. There are indeed times when localised variable definitions are in fact more elegant. But it doesn't go beyond just being more elegant. It doesn't add to the power of the language. It just addresses one of many down sides in this particular language (and every language has plenty of down sides) that you could just as well have solved with #pragma statements or lint(1) annotations. It does however introduce more ways to make mistakes and I simply don't value elegancy that much. I value consistency more. -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net