Oh noooooo!!
Doug Gwyn
gwyn at smoke.BRL.MIL
Fri Sep 8 06:08:27 AEST 1989
In article <34566 at apple.Apple.COM> ftanaka at Apple.COM (Forrest Tanaka) writes:
>I've been using gotos regularly in my C code for quite a few months--in one
>specific situation. That situation is for error handling.
Your example could be generalized as follows:
char *
SomeFunction ()
{
char *Block0;
char *Block1;
char *Block2;
if ((Block0 = AllocateMemory ()) == NULL)
goto Abort0;
if ((Block1 = AllocateMemory ()) == NULL)
goto Abort1;
if ((Block2 = AllocateMemory ()) == NULL)
goto Abort2;
return Block0;
Abort2:
DeallocateMemory (Block1);
Abort1:
DeallocateMemory (Block0);
Abort0:
return (char *) null;
}
which we ended up adopting extensively in the huge programming project
I occasionally mention. It brings a high degree of order to the error
handling process, significantly improving the chances that all actions
get unwound properly on an abort.
More information about the Comp.lang.c
mailing list