title: How to handle error conditions in a void function
body: <p>I'm making a data structures and algorithms library in C for learning purposes (so this doesn't necessarily have to be bullet-proof), and I'm wondering how void functions should handle errors on preconditions. If I have a function for destroying a list as follows:</p>
  
  <pre><code>void List_destroy(List* list) {
  
      /*
        ...
        free()'ing pointers in the list. Nothing to return.
        ...
      */
  }
  </code></pre>
  
  <p>Which has a precondition that <code>list != NULL</code>, otherwise the function will blow up in the caller's face with a segfault.</p>
  
  <p>So as far as I can tell I have a few options: one, I throw in an <code>assert()</code> statement to check the precondition, but that means the function would <em>still</em> blow up in the caller's face (which, as far as I have been told, is a big no-no when it comes to libraries), but at least I could provide an error message; or two, I check the precondition, and if it fails I jump to an error block and just <code>return;</code>, silently chugging along, but then the caller doesn't know the <code>List*</code> was NULL.</p>
  
  <p>Neither of these options seem particularly appealing. Moreover, implementing a return value for a simple destroy() function seems like it should be unnecessary.</p>
  
  <p><strong>EDIT:</strong> Thank you everyone. I settled on implementing (in all my basic list functions, actually) consistent behavior for NULL <code>List*</code> pointers being passed to the functions. All the functions jump to an error block and <code>exit(1)</code> as well as report an error message to <code>stderr</code> along the lines of "Cannot destroy NULL list." (or push, or pop, or whatever). I reasoned that there's really no sensible reason why a caller should be passing NULL <code>List*</code> pointers anyway, and if they didn't know they were then by all means I should probably let them know.</p>