title: calloc(), pointers and all bits zero
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9894013/is-null-always-zero-in-c">Is NULL always zero in C?</a>  </p>
  </blockquote>
  
  
  
  <p>The C standard states the following for <code>calloc()</code>:</p>
  
  <blockquote>
    <p>The calloc function allocates space for an array of nmemb objects, each of whose size is size. The space is initialized to all bits zero.</p>
  </blockquote>
  
  <p>with the following caveat relating to <em>all bits zero</em>:</p>
  
  <blockquote>
    <p>Note that this need not be the same as the representation of floating-point zero or a null pointer constant.</p>
  </blockquote>
  
  <p>Test program:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main()
  {
      char** list = calloc(10, sizeof(*list));
      int i;
      for (i = 0; i &lt; 10; i++)
      {
          printf("%p is-null=%d\n", list[i], NULL == list[i]);
      }
      free(list);
  
      return 0;
  }
  </code></pre>
  
  <p>I built and executed this program with the following compilers:</p>
  
  <ul>
  <li>VC7, VC8, VC9, VC10</li>
  <li>gcc v4.1.2, <a href="http://ideone.com/TNHoAF" rel="nofollow noreferrer">gcc v4.3.4</a></li>
  <li>Forte 5.8, Forte 5.10</li>
  </ul>
  
  <p>In all cases <em>all bits zero</em> is a <code>NULL</code> pointer (unless I made a mistake in the test program).</p>
  
  <p>What is the reason a <code>NULL</code> pointer is not guaranteed by the C standard to be <em>all bits zero</em> ? Out of curiousity, are there any compilers where <em>all bits zero</em> is not a <code>NULL</code> pointer ?</p>