Article View: comp.std.c
Article #3408Re: GOTO single exit point (was: Re: How to eliminate GOTO?)
From: Paul Long
Date: Fri, 08 Sep 1995 19:21
Date: Fri, 08 Sep 1995 19:21
68 lines
2504 bytes
2504 bytes
volpe@bart.crd.ge.com (Christopher R. Volpe) wrote:
[snip:the dead horse that we are beating]
>Silly contrived example using multiple returns:
>
>void manipulate_the_windows(Window *top)
>{
> Window *A, *B, *C;
>
> if (top == NULL) {
> return;
> }
>
> do_something_with_window(top);
> A = get_subwindow(top);
> if (A == NULL) {
> return;
> }
>
> do_something_different_with_window(A);
> B = get_subwindow(A);
> if (B == NULL) {
> return;
> }
>
> do_something_with_window(B);
> C = get_subwindow(B);
> if (C == NULL) {
> return;
> }
>
> /* All windows I'm looking for are good, so do it */
> do_something_weird_with_four_windows(top,A,B,C);
>
> return; /* Omit this or not as a matter of taste */
>}
Silly contrived example using one (implicit) return path:
void manipulate_the_windows(Window *top)
{
Window *A, *B, *C;
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);
}
}
}
}
}
--
Paul Long 45:29:14N 122:48:09W
plong@perf.com http://www.teleport.com/~pciwww/
"Wagging head and tail, the red-tailed fish, unsupported, turns around."
Technical Details
Message-ID:
<42q53c$9v9@news0.rain.rg.net>Path:
arc1-ca.pugleaf.net!reuter.cse.ogi.edu!gasco!rainrgnews0!usenetReferences:
<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!reuter.cse.ogi.edu!gasco!rainrgnews0!usenet From: Paul Long <plong@perf.com> Newsgroups: comp.std.c,comp.lang.c Subject: Re: GOTO single exit point (was: Re: How to eliminate GOTO?) Date: 8 Sep 1995 19:21:16 GMT Organization: Performance Computing Incorporated Message-ID: <42q53c$9v9@news0.rain.rg.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> NNTP-Posting-Host: yosemite.perf.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.1 sun4c) X-URL: news:42n1t0$18q@rdsunx.crd.ge.com