Re: Patch?: linux-2.5.59/sound/soundcore.c referenced non-existant errno variable

Horst von Brand (brand@jupiter.cs.uni-dortmund.de)
Mon, 20 Jan 2003 16:27:42 +0100


"Adam J. Richter" <adam@yggdrasil.com> said:
> To my knowledge, a goto in this case is not necessary for
> avoiding code duplication. If there are a small number of failable
> steps that may need to be unwound, you could adopt the style of my patch
> (which shortened the code slightly):
>
> if (step1() == ok) {
> if (step2() == ok) {
> if (strep3() == ok)
> return OK;
> undo_step2();
> }
> undo_step1();
> }
> return failure;

The "undo_stepX()"'s pollute the CPU's cache, and (even much worse) the
gentle reader's.

> If the nesting gets any deeper than this, then a more
> understandable solution for readability than using goto would be to
> define a separate inline routine.

Can't be done (cleanly) in many cases due to function semantics in C,
polutes CPU cache as above, screws up or gives bad code due to compiler
bugs. Plus has the gentle reader who wants to check error handling chasing
all over the place.

> In general, I recommend using goto only when it is
> topologically necessary to avoid code duplication or due to some
> compiler quirk where you want to sqeeze a few more cycles out of code
> in a critical path. That way, the use of goto basically flags these
> unusual cases for other programmers.

IMVHO, any general criterion that is not strictly based on code
understandability, possibly mitigated by a justified need of maximal speed,
is flawed. This might come close, but won't cut it for me.

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