Re: [FIXES] 2.1.125

Mark H. Wood (mwood@IUPUI.Edu)
Wed, 14 Oct 1998 13:08:14 -0500 (EST)


On Tue, 13 Oct 1998, Erik Andersen wrote:
> But in C, if you need a local variable, you can very easily add in
> a new scope in which to declare a new local variable. i.e
>
> foo++;
> megaFoo( foo);
> /* need a new scratch variable */
> {
> int x;
> for (x=0; x< foo; x++) {}
> }
>
> And when you don't need the variable any more, you just let it go out
> of scope. Behold, you now have C++ equivalent behavior (although the
> C++ syntax is more friendly).

Yeah, I learned to do stuff like that ages ago in PL/I in order to save a
few bytes on small machines, since the compiler could reuse memory that
had "lost its name" when another variable is declared in another inner
scope. These days compilers often do a much better job of
variable-lifetime analysis so I should probably stop.

There's also the question of variable lifetime in the programmer's mind as
he works through the code, but I can't decide whether I find it more
confusing to see a huge block of declarations up front and no mention of
many of these symbols until 'way down the function, or to see new
variables being created and destroyed throughout the function. (You could
break up the function into several smaller ones, and in a style course
you'd probably do that, but you might not do it in the critical path
through a gigabit router due to call/return overhead.)

-- 
Mark H. Wood, Lead System Programmer   mwood@IUPUI.Edu
Some things are not improved when made "graphical".  Imagine how crude
Kilmer's "Trees" would be if reduced to comic-book form.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/