title: Why is it necessary to cast to void** (e.g. in cudaMalloc calls)?
body: <p>The <code>cudaMalloc()</code> function is <a href="http://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__MEMORY.html#group__CUDART__MEMORY_1g37d37965bfb4803b6d4e59ff26856356" rel="nofollow noreferrer">defined</a> using:</p>
  
  <pre><code>cudaMalloc ( 
    void ** devPtr, 
    size_t size)
  </code></pre>
  
  <p>The responses <a href="https://stackoverflow.com/questions/12936986/why-does-cudamalloc-use-pointer-to-pointer">here</a> and <a href="https://stackoverflow.com/questions/7989039/use-of-cudamalloc-why-the-double-pointer">here</a> give good explanations for why the function should be defined to accept a pointer to a pointer.  </p>
  
  <p>I am less clear, however, on why we need to type cast the arguments we supply when calling the function to be type void**.  E.g. in the call to the function:</p>
  
  <pre><code>catch_status = cudaMalloc((void**)&amp;device_array, num_bytes);
  </code></pre>
  
  <p>presented <a href="https://stackoverflow.com/questions/12936986/why-does-cudamalloc-use-pointer-to-pointer">here</a>.</p>
  
  <p>As I understand it, defining a function that accepts void types is something which gives it more flexibility.  I.e. looking at the definition of the <code>cudaMalloc()</code> function, I interpret it to mean that it can accept a pointer to a pointer to any type of object.  As such, why should it be necessary to type cast <code>&amp;device_array</code> (in the example above) when calling the function.  (this syntax of such typecasting seems very prevalent in the <code>cudaMalloc()</code> examples I see throughout the web).  As long as <code>&amp;device_array</code> satisfies the condition that it is a "pointer to a pointer of any type of data", isn't that enough to (a) satisfy the function definition of the arguments <code>cudaMalloc()</code> accepts and (b) accomplish whatever programming objectives we have?</p>
  
  <p>What am I missing here?</p>