468,484 Members | 1,749 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

Void pointer dereferencing

hello friends,

I am stuck with a problem in QNX environement,

Problem
there are 3 layers in the entire software
layer 1, layer 2, layer3

From the layer1 i will be getting a void * as a parameter to a function.

From the layer2 I pass this void * to the layer 3. In the layer 3 I dynamically allocation space for a structure x, to the void pointer. But the problem is as long as the control is in the layer 3 the void * pointer is able to hold the allocated address, as soon as the control comes to the layer 2 or 1, the address is lost and it becomes 0, being a pointer that is passed as a paramter shouldnt it retian the address?

can any one please help me understand this concept.

besdt regards
shashidhar
Oct 23 '06 #1
3 3148
Banfa
9,055 Expert Mod 8TB
No the pointer is passed by value, as such you can not write the pointers value, only the value of the thing it points at.

If you want to return a pointer (to a block of allocated memory) then you need to take a pointer to it (i.e. void **)
Oct 23 '06 #2
No the pointer is passed by value, as such you can not write the pointers value, only the value of the thing it points at.

thank you for the response

If you want to return a pointer (to a block of allocated memory) then you need to take a pointer to it (i.e. void **)
but the layer1 will only pass the void *... so u mean to say layer2 has to pass void** to layer3 and in the layer3 i would have to allocate the memory
as

*ptr = (x *)malloc(sizeof(x));
am i right ...
and now the void pointer will be having the address to allocation that is made.
please correct me if i am wrong
Oct 23 '06 #3
Banfa
9,055 Expert Mod 8TB
layer 1 would pass a pointer to a void *

void *vp;

Pass(&vp);

layer 2 will pass on the void ** and your malloc line for layer 3 looks about right.
Oct 23 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Pushker Pradhan | last post: by
4 posts views Thread by Pushkar Pradhan | last post: by
188 posts views Thread by infobahn | last post: by
7 posts views Thread by sunglo | last post: by
5 posts views Thread by Stijn van Dongen | last post: by
56 posts views Thread by maadhuu | last post: by
23 posts views Thread by Eric J.Hu | last post: by
27 posts views Thread by Erik de Castro Lopo | last post: by
28 posts views Thread by junky_fellow | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.