Date: Mon, 31 Jan 2005 13:36:09 +0100 From: "Poul-Henning Kamp" <phk@phk.freebsd.dk> To: Andrew Reilly <andrew-freebsd@areilly.bpc-users.org> Cc: Paul Richards <paul@originative.co.uk> Subject: Re: c99/c++ localised variable definition Message-ID: <90392.1107174969@critter.freebsd.dk> In-Reply-To: Your message of "Mon, 31 Jan 2005 23:26:09 %2B1100." <20050131122609.GA83556@gurney.reilly.home>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?90392.1107174969>
