Article View: comp.lang.misc
Article #4394Re: GOTO controversy
From: Andrew Dalgleish
Date: Tue, 12 Mar 1996 01:23
Date: Tue, 12 Mar 1996 01:23
43 lines
2154 bytes
2154 bytes
gomberg@wcf.com wrote:
>
> This is goto-free and I think equally clear:>>>------------------------------------------------------------------------------
> HEV hev1, hev2, hev3; /* Event semaphores */
> HMTX hmtx; /* Mutex semaphore */
> void *ptr;
> if DosCreateEventSem(0, &hev1, 0, FALSE) then do;
> if DosCreateEventSem(0, &hev2, 0, FALSE) then do;
> if DosCreateEventSem(0, &hev3, 0, FALSE) then do;
> if DosCreateMutexSem(0, &hmtx, 0, FALSE) then do;
> ptr = malloc(SOME_SIZE)
> if ptr<>NULL then do;
> /* Do some stuff here */
> return TRUE; /* We did okay */ end;
> DosCloseMutexSem(hmtx); end;
> DosCloseEventSem(hev3); end;
> DosCloseEventSem(hev2); end;
> DosCloseEventSem(hev1); end;
> return FALSE;
>
> And I would assert my code is (1) a lot more PL/1-like and
> (2) a lot easier to understand.
1. I assume you have #define'd "do" and "end" as "{" and "}".
How do you encode "do {...} while(...);" ?
2. The extra semi-colons after each do & end don't achieve anything.
3. What does "<>" mean in C ?
Otherwise, this is one example where you can remove goto's without loss
of speed and improve clarity.
This doesn't mean you should never use goto's.
--
Andrew Dalgleish
Senior Software Engineer
Axon Research, Pty Ltd
6 Wallace Ave
Toorak, VIC
3142
AUSTRALIA
Tel: +61-3-9826-5538
Fax: +61-3-9824-0083
Email: andrewd@axonet.com.au
Technical Details
Message-ID:
<3144D1F7.E64@axonet.com.au>Path:
arc1-ca.pugleaf.net!yarrina.connect.com.au!usenetReferences:
<rcshlds.1.000A6705@mailserv.mta.ca> <Dn8pJ8.nqs@emi.net> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <DnwCxp.84C@clw.cs.man.ac.uk> <4hsco0$rj5@hoho.quake.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!yarrina.connect.com.au!usenet From: Andrew Dalgleish <andrewd@axonet.com.au> Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1 Subject: Re: GOTO controversy Date: Tue, 12 Mar 1996 11:23:03 +1000 Organization: Axon Research, Pty Ltd Message-ID: <3144D1F7.E64@axonet.com.au> References: <rcshlds.1.000A6705@mailserv.mta.ca> <Dn8pJ8.nqs@emi.net> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <DnwCxp.84C@clw.cs.man.ac.uk> <4hsco0$rj5@hoho.quake.net> NNTP-Posting-Host: andrew.axonet.com.au Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 2.0 (Win95; I)