Re: c99/c++ localised variable definition

From: Ben Mesander (ben_at_timing.com)
Date: 01/28/05

  • Next message: Peter Edwards: "Re: c99/c++ localised variable definition"
    Date: Fri, 28 Jan 2005 12:58:35 -0700
    To: Peter Jeremy <PeterJeremy@optushome.com.au>
    
    

    Peter Jeremy writes:
    > It is most useful for variables with a short lexical lifetime in large
    > functions. For a variable with a long lifetime - especially one which
    > is infrequently referenced - it can make it much harder to locate the
    > variable definition. It is also far less obvious what variable are
    > in scope at any point - which is an issue if you are writing some new
    > code and need a work variable.

    On the positive side, it is also very useful for allowing you to make
    things that shouldn't change really const.

    You can declare:

       const int foo = bar*GRONK + 37;

    in the middle of a block, and get a compile-time error if you try to
    change it later while maintaining the code.

    If you're forced to do all decl's at the top of a function, it's
    somewhat more work to be const correct.

    The other points you bring up are mostly big issues only if the
    functions in question are quite large, which some (but I'm not sure
    all) developers feel is indicative of other problems with the code.

    Regards,
    Ben
    _______________________________________________
    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: Peter Edwards: "Re: c99/c++ localised variable definition"