title: To GOTO or not to GOTO?
body: <p>Currently I am working on a project where goto statements are heavely used. The main purpose of goto statements is to have one cleanup section in a routine rather than multiple return statements.
  Like below:</p>
  
  <pre><code>BOOL foo()
  {
     BOOL bRetVal = FALSE;
     int *p = NULL;
  
     p = new int;
     if (p == NULL)
     {
       cout&lt;&lt;" OOM \n";
       goto Exit;
     }
  
     // Lot of code...
  
  Exit:
     if(p)
     {
       delete p;
       p = NULL;
     }
     return bRetVal;
  }
  </code></pre>
  
  <p>This makes it much easier as we can track our clean up code at one section in code, that is, after the Exit label.</p>
  
  <p>However, I have read many places it's bad practice to have goto statements.</p>
  
  <p>Currently I am reading the <em><a href="https://en.wikipedia.org/wiki/Code_Complete" rel="noreferrer">Code Complete</a></em> book, and it says that we need to use variables close to their declarations. If we use goto then we need to declare/initialize all variables before first use of goto otherwise the compiler will give errors that initialization of xx variable is skipped by the goto statement.</p>
  
  <p>Which way is right?</p>
  
  <hr>
  
  <p>From Scott's comment:</p>
  
  <p>It looks like using goto to jump from one section to another is bad as it makes the code hard to read and understand.</p>
  
  <p>But if we use goto just to go forward and to one label then it should be fine(?).</p>