Article View: comp.lang.misc
Article #4381Re: GOTO controversy
From: Charles Lindsey
Date: Thu, 07 Mar 1996 12:20
Date: Thu, 07 Mar 1996 12:20
53 lines
2172 bytes
2172 bytes
In <4hl8mt$4po@newshost.cyberramp.net> sinan@cyberramp.net (John Noland) writes:
>>Robert C Shields (rcshlds@mailserv.mta.ca) wrote:
>>Example for a good use of goto:
>>--- ????
>>------------------------------------------------------------------------------
>> HEV hev1, hev2, hev3; /* Event semaphores */
>> HMTX hmtx; /* Mutex semaphore */
>> void *ptr;
>> if (!DosCreateEventSem(0, &hev1, 0, FALSE))
>> goto hev1_failed;
>>
>> if (!DosCreateEventSem(0, &hev2, 0, FALSE))
>> goto hev2_failed;
>> if (!DosCreateEventSem(0, &hev3, 0, FALSE))
>> goto hev3_failed;
>>
>> if (!DosCreateMutexSem(0, &hmtx, 0, FALSE))
>> goto hmtx_failed;
>>
>> if ((ptr = malloc(SOME_SIZE)) == NULL)
>> goto malloc_failed;
>>
>> /* Do some stuff here */
>> return TRUE; /* We did okay */
>>
>>malloc_failed:
>> DosCloseMutexSem(hmtx);
>>hmtx_failed:
>> DosCloseEventSem(hev3);
>>hev3_failed:
>> DosCloseEventSem(hev2);
>>hev2_failed:
>> DosCloseEventSem(hev1);
>>hev1_failed:
>> return FALSE;
>The above is NOT an example of a good use for the goto statement.
Well that is what I thougut when I first saw the example, and I was about to
dash off an article like you have done. But then I looked again and saw
*exactly* what it was doing.
So if you believe there is a better way, please can we see it?
--
Charles H. Lindsey -------------------------------------------------------------
At Home, doing my own thing. Internet: chl@clw.cs.man.ac.uk
Voice/Fax: +44 161 437 4506 Janet: chl@uk.ac.man.cs.clw
Snail: 5 Clerewood Ave., CHEADLE, SK8 3JU, U.K. UUCP: mucs!clerew!chl
Technical Details
Message-ID:
<DnwCxp.84C@clw.cs.man.ac.uk>Path:
arc1-ca.pugleaf.net!cs.man.ac.uk!clerew!chlReferences:
<rcshlds.1.000A6705@mailserv.mta.ca> <Dn8pJ8.nqs@emi.net> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1 Path: arc1-ca.pugleaf.net!cs.man.ac.uk!clerew!chl From: chl@clw.cs.man.ac.uk (Charles Lindsey) Subject: Re: GOTO controversy Message-ID: <DnwCxp.84C@clw.cs.man.ac.uk> References: <rcshlds.1.000A6705@mailserv.mta.ca> <Dn8pJ8.nqs@emi.net> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> Date: Thu, 7 Mar 1996 12:20:13 GMT