Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!hascall From: hascall@atanasoff.cs.iastate.edu (John Hascall) Newsgroups: comp.lang.c Subject: Re: Oh noooooo!! Message-ID: <1488@atanasoff.cs.iastate.edu> Date: 8 Sep 89 14:24:27 GMT References: <7598@goofy.megatest.UUCP> <34566@apple.Apple.COM> <9511@chinet.chi.il.us> Reply-To: hascall@atanasoff.cs.iastate.edu.UUCP (John Hascall) Organization: Iowa State Univ. Computation Center Lines: 51 In article <9511@chinet.chi.il.us> john@chinet.chi.il.us (John Mundt) writes: }In article <34566@apple.Apple.COM> ftanaka@Apple.COM (Forrest Tanaka) writes: }>I've been using gotos regularly in my C code for quite a few months--in one }Pathetic justifications deleted and sample of code follows. }char * SomeFunction () { } char *Block0, *Block1, *Block2; } Block0 = Block1 = Block2 = null; } if ((Block0 = AllocateMemory ()) != null } && (Block1 = AllocateMemory ()) != null } && (Block2 = AllocateMemory ()) != null) } return Block0; } if (Block0 != null) } DeallocateMemory (Block0); } if (Block1 != null) } DeallocateMemory (Block1); } if (block2 != null) } DeallocateMemory (Block2); } return null; } } The code: if (Block2 != null) DeallocateMemory (Block2); is useless, if Block2 != null you have already returned above! How about: #define ALLOC(ptr, type) ((ptr = (type*)malloc(sizeof(type))) != NULL) ... if (ALLOC(B0, FOO)) { if (ALLOC(B1, BAR)) { if (ALLOC(B2, BAZ)) { /* all alloced ok, do something with it */ return (B0); } FREE(B1); } FREE(B0); } return (NULL); /* couldn't alloc something */ John Hascall