Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, the way to handle that pattern is with nested gotos:

    a = acquire(A);
    if (!a) goto err_a;

    b = acquire(B);
    if (!b) goto err_b;

    c = acquire(C);
    if (!c) goto err_c;

    do_stuff(a,b,c);

  err_c:
    release(b);
  err_b:
    release(a);
  err_a:
    return;
This is precisely why goto is not universally evil.


Consider:

  a = acquire(A);
  if (a)
  {
  	b = acquire(B);
  	if (b)
  	{
  		c = acquire(C);
  		if (c)
  		{
  			do_stuff(a,b,c);
  		}
  		release(b);
  	}
  	release(a);
  }
  return;




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: