Answer: yes, you can pass void* by reference, and the error you get is not related to this. The problem is that if you have a function that takes void* by reference, then you can only pass variables that are actually void* as a parameter. There is a good reason for this. For example, suppose you have this function:
void MyFunction(void*& ptr) { ptr = malloc(137);
The above code is illegal due to the specified call and not without reason. If we could pass myIntArray into MyFunction , it would be reassigned to point to a buffer of type void* , which is not an int array. Therefore, when returning from a function, your int* will point to an array of type void* , undermining the type system. This does not mean that C ++ has a strong type system - it is not, but if you are going to undermine it, you must explicitly introduce some casts.
Similarly, you cannot:
void MyFunction(void*& ptr) { ptr = malloc(137);
As a good reference, why can't you do this, think about this code:
void OtherFunction(int& myInt) { myInt = 137; } double myDouble; OtherFunction((int)myDouble);
This is not legal, because if you tried to pass the function that int& took to double , then since int and double have fundamentally different binary representations, you will end up hiding the double bit with meaningless data. If this cast should be legal, one could do Bad Things like that.
So yes, you can take void* & , but if you need it, you have to go through real void* s. As Eric noted above, if you want to free zero too, then pointer patterns will be available.
If you really want to pass this function to uint_8* , you can do it like this:
uint_8* uPtr = void* ptr = uPtr; FreeAndNull(ptr); uPtr = (uint_8*) ptr;
This requires explicit casting to tell the compiler, βYes, I know this might not be safe, but I'll do it anyway.β
Hope this helps!