Re: [FIXES] 2.1.125

Erik Andersen (andersen@inconnect.com)
Tue, 13 Oct 1998 09:14:17 -0600 (MDT)


On Mon, 12 Oct 1998, Mathew G Monroe wrote:

> Excerpts from internet.computing.linux-kernel: 10-Oct-98 Re: [FIXES]
> 2.1.125 by Oliver Xymoron@waste.org
> > > [btw: can someone explain me why in linux kernel I can't declare var
> > > inside of the proc, but instead it has to be at beginning of it. I think
> > > in 'normal' c programs you can do that]
> >
> > Because you've been writing your 'normal' C programs with a C++ compiler.
> > In ANSI C, variable declarations must preceed all other statements inside
> > a given scope. Further, variable initialization is limited to simple
> > assignments.
> >
> > This is one of the few features of C++ that would apply well to the
> > kernel, I think - there are numerous multiple-page functions that could be
> > clarified by local declarations. The kernel already heavily relies on
> > inline functions, which are standard in C++ but not in C.
>
> C9X drafts have included this feature for quite some time. So hopeful
> sometime next year when C9X becomes standard this can be used. Now that
> brings up a question, what do people thing about using it?
>
> Matt Monroe
>

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).

-Erik

--
Erik B. Andersen   Web:    http://www.inconnect.com/~andersen/ 
                   email:  andersee@debian.org
--This message was written using 73% post-consumer electrons--

- 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/