[linux-elitists] Goto vs. named scopes

Michael Bacarella mbac@netgraft.com
Sat Jan 11 10:24:12 PST 2003


> Allow all scopes to be named, and allow break and continue to operate
> with those names. Add to those a 'restart' operation and you're pretty
> much all set.
> 
> outer: {
> 	get_lock: for (...) {
> 		sleep();
> 		if (interrupted)
> 			restart get_lock;
> 		if (error)
> 			break outer;
> 	}
> 	more code;
> }


That is one common use of goto in the linux kernel.

The other common use is in cleanup routines.

{
    r = open_resource()
    if (!r)
        goto out;
   
    lock = allocate_lock()
    if (!lock)
        goto resource_out;

    if (r->thingy) {
        lock->raise();
        some_thingies();
        if (can_do_thingy()) {
            other_thingies();
            if (exceptional_circumstance)
                goto release_lock_out;
            more_thingies();
            finish_thingies();
        }
        lock->lower();
    }

release_lock_out:
    lock->lower(); 
lock_out:
    free_lock(lock); 
resource_out:
    close_resource(r);
out:
    return foo;
}

Not the most streamlined example but I think it illustrates
my point.  Maybe I haven't thought about it enough, but could
your extensions make that better?

-M




More information about the linux-elitists mailing list