Re: [PATCH] gcc-3.0 warnings

Tim Wright (timw@splhi.com)
Fri, 23 Mar 2001 16:31:29 -0800


On Fri, Mar 23, 2001 at 11:59:09PM +0100, J . A . Magallon wrote:
>
> On 03.23 Linus Torvalds wrote:
> >
> > I agree. I'd much prefer that syntax also.
> >
> > Or just remove the "default:" altogether, when it doesn't make any
> > difference.
> >
>
> Well, at last some sense. The same is with that ugly out: at the end
> of the function. Just change all that 'goto out' for a return.
> It does not matter, -O2 is going to do what it wants.
>

This has nothing to do with fastpathing and object code optimization. C
doesn't have exception handling, so you either have to remember to undo
allocations etc. in failure cases all through the code, or you stick your
undo code at the end of the function and have all failure cases jump to the
relevant label. It's not pretty, but it's much less error-prone e.g.

func()
{
error = 0;
a = alloc_something();
if (some failure) {
error = XXX;
goto out;
}
b = alloc_something_else();
if (some other failure) {
error = YYY;
goto out1;
}
...
out1:
dealloc(b);
out:
dealloc(a);
return(error);
}

This is arguably easier to follow and less likely to get broken than the
alternative of embedding all the unwind code at each error point.

Tim

--
Tim Wright - timw@splhi.com or timw@aracnet.com or twright@us.ibm.com
IBM Linux Technology Center, Beaverton, Oregon
Interested in Linux scalability ? Look at http://lse.sourceforge.net/
"Nobody ever said I was charming, they said "Rimmer, you're a git!"" RD VI
-
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/