title: If `malloc(0)` returns a non-null pointer, can I pass that to `free`?
body: <p>I've been reading over discussions of how <code>malloc</code> behaves when you request a zero sized block.</p>
  
  <p>I understand that the behavior of <code>malloc(0)</code> is implementation-defined, and it is supposed to either return a null pointer, <em>or</em> a non-null pointer that I am nonetheless not supposed to access. (Which makes sense, since there's no guarantee that it points to any usable memory.)</p>
  
  <p>However, if a get such a nonaccessable non-null pointer, am I allowed to pass it to <code>free</code> in the usual way? Or is that illegal, since the pointer I get from <code>malloc(0)</code> may not point to an actual allocated block of memory?</p>
  
  <p>Concretely, does the following code have well-defined behavior:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      int* x = (int*) malloc(0);
      if (x == NULL) {
          printf("Got NULL\n");
          return 0;
      } else {
          printf("Got nonnull %p\n", x);
      }
      free(x); // is calling `free` here okay?
  }
  </code></pre>