This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: const warning...
On Sat, 2003-07-05 at 08:31, Fergus Henderson wrote:
> [...]
> void print_squares(void) {
> int i;
> for (i = 0; i < 10; i++) {
> const int sqr_i = i * i;
> printf("%d squared is %d\n", i, sqr_i);
> }
> }
>
> If you are arguing that there is a fundamental and important difference
> between these two code snippets, then I would beg to differ. There is
> a difference, certainly, but I don't find it especially important.
> While I agree that it is better style to declare variables in their
> closest enclosing scope, I wouldn't say that it makes such a *fundamental*
> difference to the code if you instead declare them at the top of the function.
On a 5 lines subprogram it doesn't make a difference, on a 100 lines
one with a dozen of declarations, it makes a huge difference if
90% of those are marked constant and put in their proper scope.
Also when doing code inspection on imperative languages, you get a good
feeling when most things are constant: no variable means no
uninitialized variable bug :).
Laurent