473,386 Members | 1,610 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,386 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 3447
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.