The cudaMalloc()
function is defined using:
cudaMalloc (
void ** devPtr,
size_t size)
The responses here and here give good explanations for why the function should be defined to accept a pointer to a pointer.
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:
catch_status = cudaMalloc((void**)&device_array, num_bytes);
presented here.
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 cudaMalloc()
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 &device_array
(in the example above) when calling the function. (this syntax of such typecasting seems very prevalent in the cudaMalloc()
examples I see throughout the web). As long as &device_array
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 cudaMalloc()
accepts and (b) accomplish whatever programming objectives we have?
What am I missing here?