Question: C Concepts
respected sir, Can I use a void ** pointer as a parameter so that a function can accept a generic pointer by reference?
I have a function
extern int f(int *); which accepts a pointer to an int. How can I pass a constant by reference? A call like f(&5);
doesn't seem to work.
In C language you could not write a function which returned generic pointers indirectly via a hypothetical void * pointer because it is not a generic pointer to pointer. You could not passed a void *, but rather a double ** when you will tried to use it for declaring and calling :
double *dptr; void *vptr = dptr; func(&vptr); dptr = vptr;
If the void ** pointer pointed to and is not a void *, and the size and representation of void * is different, then the compiler will unable to access it correctly.
It can not be done directly, for doing this you have to declare a variable temporarily and then the address of it passed to the function
int a = 5; f(&a);