gotos in kernel [Was: Re: any chance of 2.6.0-test*?]

From: Horst von Brand (brand@jupiter.cs.uni-dortmund.de)
Date: Mon Jan 13 2003 - 05:32:17 EST


Rob Wilkens <robw@optonline.net> said:
> I'm REALLY opposed to the use of the word "goto" in any code where it's
> not needed. OF course, I'm a linux kernel newbie, so I'm in no position
> to comment

My, my, my, an anti-goto zealot now.

> Let me comment below the relevant code snippet below as to how I would
> change it:
>
> On Sun, 2003-01-12 at 14:15, Linus Torvalds wrote:
> > if (spin_trylock(&tty_lock.lock))
> > goto got_lock;
> > if (tsk == tty_lock.lock_owner) {
> > WARN_ON(!tty_lock.lock_count);
> > tty_lock.lock_count++;
> > return flags;
> > }
> > spin_lock(&tty_lock.lock);
> > got_lock:
> > WARN_ON(tty_lock.lock_owner);
> <etc...>
>
> I would change it to something like the following (without testing the
> code through a compiler or anything to see if it's valid):

It just to happens that sometimes the compiler generates stupid code for
goto-less solutions. While the famous "no goto needed" theorem is certainly
true, it duplicates lots of code to get rid of gotos, and that is a no -
never - only over my dead body proposition in a kernel that tries to be as
fast as humanly possible.

And if used with care and good taste, a goto can lead to clearer, more
understandable (and thus more probably correct) code. Just look up what
sort of "programming style" Dijkstra was complaining about when asking to
ban gotos, and what D. E. Knuth has to say on structured programming with
gotos.

--
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Jan 15 2003 - 22:00:45 EST