473,385 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 3446
Banfa
9,065 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,065 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

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

Similar topics

9
by: Pushker Pradhan | last post by:
I've a function which accepts void * as the arg because the actual datatype can be char or float or anything. The fuction: void convolve(void *x, float *convx, uint32 numrowsx, uint32 numcolsx,...
4
by: Pushkar Pradhan | last post by:
I have some functions which take as i/p a buffer (it can be float, char, or 16 bit, int etc.). The result is another o/p buffer, its type is also flexible (it could be a float, char etc.). I try...
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
7
by: sunglo | last post by:
My doubt comes from trying to understand how thread return values work (I know, it's off topic here), and I'm wondering about the meaning of the "void **" parameter that pthread_join expects (I...
5
by: Stijn van Dongen | last post by:
A question about void*. I have a hash library where the hash create function accepts functions unsigned (*hash)(const void *a) int (*cmp) (const void *a, const void *b) The insert function...
56
by: maadhuu | last post by:
hello, this is a piece of code ,which is giving an error. #include<stdio.h> int main() { int a =10; void *p = &a; printf("%d ", *p ); //error....why should it //be an error ?can't the...
23
by: Eric J.Hu | last post by:
Hi, I have following code, want do pointer convert. It always complain: vcnvt.c: In function `main': vcnvt.c:20: warning: dereferencing `void *' pointer vcnvt.c:20: request for member `key'...
27
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in...
28
by: junky_fellow | last post by:
Guys, Consider a function func(void **var) { /* In function I need to typecast the variable var as (int **) I mean to say, I need to access var as (int **) }
3
by: sritejv | last post by:
Hello everyone, I am having a problem with typecasting void pointers.I have read the pointer basics but still cant understand why the following test code doesnt work. void *xyz; struct abcd...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.