Pointer sizes and dereferencing a void *
Let's say I have a function that receives a void ** and I want to dereference the pointer and do something to whatever it points to. I know right away I would have to cast the void ** to something else.
If I just wanted to free whatever the void ** points to, I imagine this should work, even though it looks quite ugly:
Code:
void mgfree(void **p)
{
if(p != NULL)
{
free(*((char **)p));
*((char **)p) = NULL;
}
return;
}
So, basically, will the above block of code free the block of memory pointed to by p for any data type?
Are there any assumptions I should or should not make regarding pointer sizes on different platforms?
Edit: I just want to add that I'm asking if this is guarenteed to behave the same way on all systems.