Re: c99/c++ localised variable definition
From: Poul-Henning Kamp (phk_at_phk.freebsd.dk)
Date: 01/31/05
- Previous message: Andrew Reilly: "Re: c99/c++ localised variable definition"
- In reply to: Andrew Reilly: "Re: c99/c++ localised variable definition"
- Next in thread: Ulrich Spoerlein: "Re: c99/c++ localised variable definition"
- Reply: Ulrich Spoerlein: "Re: c99/c++ localised variable definition"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: Andrew Reilly <andrew-freebsd@areilly.bpc-users.org> Date: Mon, 31 Jan 2005 13:36:09 +0100
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. _______________________________________________ freebsd-arch@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-arch To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
- Previous message: Andrew Reilly: "Re: c99/c++ localised variable definition"
- In reply to: Andrew Reilly: "Re: c99/c++ localised variable definition"
- Next in thread: Ulrich Spoerlein: "Re: c99/c++ localised variable definition"
- Reply: Ulrich Spoerlein: "Re: c99/c++ localised variable definition"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|