🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3480

Re: Multi-level break and elimination of GOTO

#3480
From: Paul Long
Date: Tue, 14 Nov 1995 03:36
62 lines
3029 bytes
andrewd@agnus.livewire.com.au (Andrew Dunbar) wrote:
>Greg Comeau (comeau@panix.com) wrote:
[snip]
>: The real problem I have with this proposal is that it only considers `for'
>: (and probably `while').  If to be stronger, it could be more general than
>: just those, plus consider appropriateness of special cases.
>: Even with that though, no doubt we still wouldn't see it fly...
>: 
>I intended them to be used in any construct where a break would apply:
>do, for, switch, while
>
>Somebody mentioned 'if' but I couldn't see a use for it.

Oh, I'm sure somebody'd find a use for it and really like it. Here's
how it could be (ab)used with an if statement.

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

        if check_parms (top == NULL)
            break check_parms;
        else {
            do_something_with_window(top);
            A = get_subwindow(top);
            if (A == NULL)
                break check_parms;

            do_something_different_with_window(A);
            B = get_subwindow(A);
            if (B == NULL)
                break check_parms;

            do_something_with_window(B);
            C = get_subwindow(B);
            if (C == NULL)
                break check_parms;

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

            return;
        }

        /* Do error handling here */
    }

Ugly, huh, early return and all? People do this sort of thing, though.
What the programmer is doing here would be better served by a labeled
compound statement and breaks to leave it (or situation indicators).
Gotos are currently used. IMO, though, the best solution would be to
rewrite the logic as something more conventional.

BTW, this example came from something someone posted to comp.std.c
awhile back. Look familiar?

-- 
Paul Long         plong@perf.com       http://www.teleport.com/~pciwww/
  "A perfect method should not only be an efficient one, as respects
  the accomplishment of the objects for which it is designed, but
  should in all its parts and processes manifest a certain unity and
  harmony." - George Boole, _An Investigation of the Laws of Thought_
Technical Details
Message-ID: <4892se$np@news0.rain.rg.net>
Path: arc1-ca.pugleaf.net!newsfeed.internetmci.com!psgrain!rainrgnews0!usenet
References: <DF8FE3.97H@news.cern.ch> <rnbohuqj8p3.fsf@euax7i3c01.eua.ericsson.se> <DHpCK1.HyG@kroete2.freinet.de> <480oqa$l1j@panix.com> <488orf$bfb@news.mel.aone.net.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsfeed.internetmci.com!psgrain!rainrgnews0!usenet
From: Paul Long <plong@perf.com>
Newsgroups: comp.std.c,comp.lang.c
Subject: Re: Multi-level break and elimination of GOTO
Date: 14 Nov 1995 03:36:46 GMT
Organization: Performance Computing Incorporated
Message-ID: <4892se$np@news0.rain.rg.net>
References: <DF8FE3.97H@news.cern.ch> <rnbohuqj8p3.fsf@euax7i3c01.eua.ericsson.se> <DHpCK1.HyG@kroete2.freinet.de> <480oqa$l1j@panix.com> <488orf$bfb@news.mel.aone.net.au>
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:488orf$bfb@news.mel.aone.net.au