title: void pointers: difference between C and C++
body: <p>I'm trying to understand the differences between C and C++ with regards to void pointers. the following compiles in C but not C++ (all compilations done with gcc/g++ -ansi -pedantic -Wall):</p>
  
  <pre><code>int* p = malloc(sizeof(int));
  </code></pre>
  
  <p>Because <code>malloc</code> returns <code>void*</code>, which C++ doesn't allow to assign to <code>int*</code> while C does allow that.</p>
  
  <p>However, here:</p>
  
  <pre><code>void foo(void* vptr)
  {
  }
  
  int main()
  {
      int* p = (int*) malloc(sizeof(int));
      foo(p);
      return 0;
  }
  </code></pre>
  
  <p>Both C++ and C compile it with no complains. Why?</p>
  
  <p>K&amp;R2 say:</p>
  
  <blockquote>
    <p>Any pointer to an object may be
    converted to type <code>void *</code> without loss
    of information. If the result is
    converted back to the original pointer
    type, the original pointer is
    recovered.</p>
  </blockquote>
  
  <p>And this pretty sums all there is about <code>void*</code> conversions in C. What does C++ standard dictate?</p>