From owner-freebsd-arch@FreeBSD.ORG Mon Jan 31 12:36:18 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 D5D0616A4CE for ; Mon, 31 Jan 2005 12:36:18 +0000 (GMT) Received: from critter.freebsd.dk (f170.freebsd.dk [212.242.86.170]) by mx1.FreeBSD.org (Postfix) with ESMTP id 404A143D48 for ; Mon, 31 Jan 2005 12:36:18 +0000 (GMT) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.13.1/8.13.1) with ESMTP id j0VCa9DH090393; Mon, 31 Jan 2005 13:36:09 +0100 (CET) (envelope-from phk@critter.freebsd.dk) To: Andrew Reilly From: "Poul-Henning Kamp" In-Reply-To: Your message of "Mon, 31 Jan 2005 23:26:09 +1100." <20050131122609.GA83556@gurney.reilly.home> Date: Mon, 31 Jan 2005 13:36:09 +0100 Message-ID: <90392.1107174969@critter.freebsd.dk> Sender: phk@critter.freebsd.dk cc: arch@freebsd.org cc: Paul Richards 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: Mon, 31 Jan 2005 12:36:19 -0000 In message <20050131122609.GA83556@gurney.reilly.home>, Andrew Reilly writes: >If you carelessly c++-ify a loop like: > > for (int i = 0; i < N; i++) > { > if (some_condition(i)) break; > } > do_something_with(i); /* use finishing index */ > >you can miss the fact that the value of i is used outside of the >loop. The newly created scope for "i" shadows the presumably >pre-existing definition of i at the top of the function, which >is what do_something_with() gets to see. I would _really_ hope we have the compiler warning about this already ? -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.