🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #4385

GOTO controversy

#4385
From: Tor Iver Wilhelmsen
Date: Fri, 08 Mar 1996 10:29
50 lines
2044 bytes
chl@clw.cs.man.ac.uk (Charles Lindsey) writes:
>
>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?

I have a potential solution: The sample below utilizes the "fall-through"
in C's switch-statement to undo what has been done in the reverse order
required.

Of course, using break is only _potentially_ nicer than a goto. At least
in this case.

- Tor Iver 

--- BEGIN included text ---

#define once while(0)

void main(void)
{
  int btracksteps=0; /* Used to keep a count for backtracking. */

  do
  {
    if (!doSomething())
      break;
    if (!doSomethingElse())
      { btracksteps=1; break; }
     /* ... */
  }
  once;

switch(btracksteps) {
  case 10: UndoSomethingWayDownInThePrecedingCode();
      /* ... */
  case 2: UndoSomethingElse();
  case 1: UndoSomething();
 } 

}

--- END included text ---
-- 
Tor Iver Wilhelmsen <toriver@pvv.unit.no> Approx. M. Sc. in CS from NTH, Norway 
Siviling. Tor I. Wilhelmsen // c/o ESD Nordic // Postboks 226 // 1411 Kolbotn
All opinions above invisible unless expressed or put in a blender. Whatever.
Info: http://www.pvv.unit.no/~toriver/  Member of The Software Workshop, NTNU
Technical Details
Message-ID: <4hp268$rs6@due.unit.no>
Path: arc1-ca.pugleaf.net!bigblue.pvv.unit.no!toriver
References: <rcshlds.1.000A6705@mailserv.mta.ca> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <DnwCxp.84C@clw.cs.man.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!bigblue.pvv.unit.no!toriver
From: toriver@bigblue.pvv.unit.no (Tor Iver Wilhelmsen)
Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1
Subject: GOTO controversy
Supersedes: <4hp1vn$rqr@due.unit.no>
Date: 8 Mar 1996 10:29:28 GMT
Organization: or.gan.i.za.tion, n., ... 5. a body of persons organized for some end or work. (Webster)
Message-ID: <4hp268$rs6@due.unit.no>
References: <rcshlds.1.000A6705@mailserv.mta.ca> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <DnwCxp.84C@clw.cs.man.ac.uk>
NNTP-Posting-Host: bigblue.pvv.unit.no
Summary: C backtracking made... well, a little better :-)
Keywords: C,backtracking,goto