🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3411

Re: GOTO single exit point (was: Re: How to eliminate GOTO?)

#3411
From: Peter Curran
Date: Sat, 09 Sep 1995 13:56
40 lines
1775 bytes
volpe@bart.crd.ge.com (Christopher R. Volpe) wrote:

[snip]

>Silly contrived example using multiple returns:

[which I won't repost[

Since I got myself into this, here's a solution:

void manipulate_the_windows(Window *top)
{
  Window *A = NULL, *B = NULL *C = NULL;

    if (top != NULL) {
       do_something_with_window(top);
       A = get_subwindow(top);
    }

    if (A != NULL) {
       do_something_different_with_window(A);
       B = get_subwindow(A);
    }

    if (B != NULL) {
       do_something_with_window(B);
       C = get_subwindow(B);
     }

   if (C != NULL)
      /* All windows I'm looking for are good, so do it  */ 
      do_something_weird_with_four_windows(top,A,B,C);
}

I'm not sure that this is exactly how I'd write this in a real-world
situation, but it does the job without multiple returns and without
deep nesting.

--
Peter Curran                               pcurran@inforamp.net
Technical Details
Message-ID: <42s5su$4h8@inforamp.net>
Path: arc1-ca.pugleaf.net!inforamp.net!usenet
References: <3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de> <41glno$3a0@caip.rutgers.edu> <41iebe$kec@news0.rain.rg.net> <41pm80$skp@inferno.mpx.com.au> <DE02nC.B58@eskimo.com> <41t0sb$15e@news0.rain.rg.net> <DE6G2z.JJD@crdnns.crd.ge.com> <4258ak$cj7@news0.rain.rg.net> <42hmj1$96o@rdsunx.crd.ge.com> <42l7s7$2id@news0.rain.rg.net> <42n1t0$18q@rdsunx.crd.ge.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!inforamp.net!usenet
From: pcurran@inforamp.net (Peter Curran)
Newsgroups: comp.std.c,comp.lang.c
Subject: Re: GOTO single exit point (was: Re: How to eliminate GOTO?)
Date: Sat, 09 Sep 1995 13:56:49 GMT
Organization: InfoRamp Inc., Toronto, Ontario (416) 363-9100
Message-ID: <42s5su$4h8@inforamp.net>
References: <3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de> <41glno$3a0@caip.rutgers.edu> <41iebe$kec@news0.rain.rg.net> <41pm80$skp@inferno.mpx.com.au> <DE02nC.B58@eskimo.com> <41t0sb$15e@news0.rain.rg.net> <DE6G2z.JJD@crdnns.crd.ge.com> <4258ak$cj7@news0.rain.rg.net> <42hmj1$96o@rdsunx.crd.ge.com> <42l7s7$2id@news0.rain.rg.net> <42n1t0$18q@rdsunx.crd.ge.com>
Reply-To: pcurran@inforamp.net
NNTP-Posting-Host: ts5-15.inforamp.net
X-Newsreader: Forte Free Agent 1.0.82