Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Jan 2005 12:58:35 -0700
From:      Ben Mesander <ben@timing.com>
To:        Peter Jeremy <PeterJeremy@optushome.com.au>
Cc:        Paul Richards <paul@originative.co.uk>
Subject:   Re: c99/c++ localised variable definition
Message-ID:  <16890.39275.761277.609543@piglet.timing.com>
In-Reply-To: <20050128183611.GG32122@cirb503493.alcatel.com.au>
References:  <20050128173327.GI61409@myrddin.originative.co.uk> <20050128183611.GG32122@cirb503493.alcatel.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?16890.39275.761277.609543>