title: Quit the whole program early in C?
body: <p>Generally say I have some functions <code>step1</code> <code>step2</code> ... and they are called successively:</p>
  
  <pre><code>int main()
  {
    ...
    step1();  // something wrong detected and need to break out of the whole program
    step2();
    step3();
    ...
  }
  </code></pre>
  
  <p>How can I break out from <code>step1</code> and skip all the rest of code to terminate <code>main()</code> function? </p>
  
  <p>Currently I can only think of setting a global variable like <code>bool isErr</code> as a flag so that </p>
  
  <pre><code>step1();  // error detected and isErr is set to 1 inside step1()
  if (isErr)
    return;
  step2();
  ...
  </code></pre>
  
  <p>Are there better or more 'canonical' approaches? </p>
  
  <p>BTW I've heard that <code>goto</code> is bad so I discard it :)</p>