I have a void** p2 variable created like for example
int x = 10;
void* p = &x;
void** p2 = &p;
This is created in a function. How can I, using parameters or return value, pass this p2 in a way that p2 and * p2 both keep their exact value. I did not succeed in finding any solution. Please give me a short example, anything would do.
Maybe some details could help:
class ShmItem
{
public:
void* start;
void** vtable;
};
this class is global, its part of a global vector.
now in my function.
item.vtable = &item.start;
shm->address = item.vtable;
where item start holds the return value of mmap.
shm is an parameter object where address is of type void**.
Now when I return to the caller voila the value of item.start changes (in the shm->address)…
Sorry, I have found the bug, which has nothing to do with pointer. Can I delete this thread? Because the question makes no sense any more. (Although Carlos’ way of passing double pointers across funcion calls is a good idea which helped me, so I marked it as answered).
I’m assuming you’re using C right?
So, I think you need to do two things.
First, declare you double pointer variable outside the function so it is in scope after the function returns.
Second, declare your function such that it receives and returns a void ** param that will hold the value you want, like so:
You could also declare myfunc to return void and call myfunc with p2 without the assignment construct.