I want to have a void*
as a function parameter and then inside a function modify that pointer (change it to NULL
).
Code below doesn't change memory1
to null
after function call. How can I change that.
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
void myFree(void**freeMemoryPointer){
/*some code*/
*freeMemoryPointer=NULL;
}
int main(){
void *memory1 = mmap(NULL, getpagesize() , PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);//example
printf("\nCurrent pointer: %p\n", memory1);
myFree(memory1);
printf("\nShould show null: %p\n", memory1);
}
I've also tried this and it works:
myFree((void*)&memory1);
However I need to set void*
as a function parameter and not (void*)&void*
.