Re: Poll: global buffers

From: Mike Breuer (mbreuer@new.rr.com)
Date: 07/21/01


From: "George Greer" <greerga@CIRCLEMUD.ORG>
> I'd rather have:
>
>           val = badval;
>           if ((foo = blah()) == fail)
>             return val;
>           if ((bar = blarg()) == fail)
>             goto cleanup1;
>           if ((baz = blarf()) == fail)
>             goto cleanup2;
>           if ((qux = barg()) == fail)
>             goto cleanup3;
>           do_something
>           val = goodval;
>
>         cleanup3:
>           cleanup(baz);
>         cleanup2:
>           cleanup(bar);
>         cleanup1:
>           cleanup(foo);
>           return val;

Interesting example in that it is only relevant if baz, bar and foo are
global.  Otherwise, it doesn't matter if you clean them all up at the end,
or clean them up as you go, since blarg(), blarf() and barg() don't use the
previously retrieved values.  So, if they are all locals, you can get just
as much mileage out of:

if ((foo = blah()) == fail || cleanup(foo) ||
    (bar = blarg()) == fail || cleanup(bar) ||
    (baz = blarf()) == fail || cleanup(baz) ||
    (qux = barg()) == fail || cleanup(qux))
  return badval;
return goodval;

As long as cleanup returns zero, this works just as well.  It's about the
same efficiency when compiled.  I also cleaned up qux, but then you know
better as to whether that is necessary, since it's your example.  But then,
we're all just playing Devil's advocate here, right?  :-)

Mike

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST