Re: c99/c++ localised variable definition

From: Poul-Henning Kamp (phk_at_phk.freebsd.dk)
Date: 01/31/05

  • Next message: Paul Richards: "Re: c99/c++ localised variable definition"
    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"
    

  • Next message: Paul Richards: "Re: c99/c++ localised variable definition"

    Relevant Pages

    • [REVIEW/TEST] "phk_bufwork" branch in p4
      ... FreeBSD committer ... | BSD since 4.3-tahoe ... Never attribute to malice what can adequately be explained by incompetence. ...
      (freebsd-current)
    • COMPAT_SUNOS lovers anywere ?
      ... | UNIX since Zilog Zeus 3.20 ... FreeBSD committer ... | BSD since 4.3-tahoe ... Never attribute to malice what can adequately be explained by incompetence. ...
      (freebsd-arch)
    • Re: headsup: swap_pager.c
      ... | UNIX since Zilog Zeus 3.20 ... FreeBSD committer ... | BSD since 4.3-tahoe ... Never attribute to malice what can adequately be explained by incompetence. ...
      (freebsd-arch)
    • Re: scsi-cd + GEOM
      ... | UNIX since Zilog Zeus 3.20 ... FreeBSD committer ... | BSD since 4.3-tahoe ... Never attribute to malice what can adequately be explained by incompetence. ...
      (freebsd-current)
    • diskless booting is børked...
      ... | UNIX since Zilog Zeus 3.20 ... FreeBSD committer ... | BSD since 4.3-tahoe ... Never attribute to malice what can adequately be explained by incompetence. ...
      (freebsd-current)