🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3410

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

#3410
From: halasz
Date: Fri, 08 Sep 1995 22:36
50 lines
1843 bytes
In article <42q81a$s2t@rdsunx.crd.ge.com>, volpe@bart.crd.ge.com (Christopher R. Volpe) writes
: Notice how the diagnostics grow further and further away from the test which
: causes them to be produced? This is what I find difficult to follow. I don't
: know about you, but I've shot myself in the foot on more than one occasion as
: a result of having one too many or one too few closing braces deeply nested.
: I find it much easier to follow code that doesn't have five levels of
: indentation.  

You hav a point, but there is no need for the error-reporting to grow bad:

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

  if (top == NULL) {
    printf("Error: Top is NULL\n");
  }
  else 
  {
    do_something_with_window(top);
    A = get_subwindow(top);

    if (A == NULL) {
      printf("Error: A is NULL\n");
    }
    else
    {
      do_something_different_with_window(A);
      B = get_subwindow(A);

      if (B == NULL) {
        printf("Error: B is NULL\n");
      }
      else
      {
        do_something_with_window(B);
        C = get_subwindow(B);

        if (C == NULL) {
          printf("Error: C is NULL\n");
        }
	else
        {
          /* All windows I'm looking for are good, so do it */
          do_something_weird_with_four_windows(top,A,B,C);
        }
      }
    }
  }
}
Technical Details
Message-ID: <42qgh7$j1h@caip.rutgers.edu>
Path: arc1-ca.pugleaf.net!caip.rutgers.edu!not-for-mail
References: <3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de> <42q81a$s2t@rdsunx.crd.ge.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!caip.rutgers.edu!not-for-mail
From: halasz@caip.rutgers.edu
Newsgroups: comp.std.c,comp.lang.c
Subject: Re: GOTO single exit point (was: Re: How to eliminate GOTO?)
Followup-To: comp.std.c
Date: 8 Sep 1995 18:36:23 -0400
Organization: Rutgers University
Message-ID: <42qgh7$j1h@caip.rutgers.edu>
References: <3vn1ht$kj8@martha.utk.edu> <41cke4$gtd@sparcserver.lrz-muenchen.de> <42q81a$s2t@rdsunx.crd.ge.com>
NNTP-Posting-Host: caip.rutgers.edu