title: Should we use exit() in C?
body: <p>There is <a href="https://stackoverflow.com/questions/30250934/how-to-end-c-code">question</a> about using <code>exit</code> in C++. The answer discusses that it is not good idea mainly because of RAII, e.g., if <code>exit</code> is called somewhere in code, destructors of objects will not be called, hence, if for example a destructor was meant to write data to file, this will not happen, because the destructor was not called.</p>
  <p>I was interested how is this situation in C. Are similar issues applicable also in C? I thought since in C we don't use constructors/destructors, situation might be different in C. So is it ok to use <code>exit</code> in C? For example I have seen following functions sometimes used in C:</p>
  <pre><code>void die(const char *message)
  {
      if(errno) {
          perror(message);
      } else {
          printf(&quot;ERROR: %s\n&quot;, message);
      }
  
      exit(1);
  }
  </code></pre>