Hi any one please tell me why the warning is generated when the address of pointer to a local variable is passed.

The following is the warning generated:
Icore.c:228: warning: passing argument 3 of foo from incompatible pointer type

The function declaration is:
int foo(void * , int , void**);


The following is the function definition:
int foo (void * inputbuffer, int sizeofinputbuffer, void** outputbuffer)
{
................
.............
}

The above function is invoked as:

unsigned char inputbuffer[] = {0x34,0x45,0x67,0x12,0x76};
int sizeofinputbuffer = 5;
unsigned char * outputbuffer = NULL;
int Total ;
Total = foo (inputbuffer, sizeofinputbuffer, &outputbuffer);

Thanks,
Prashanth

Actually my intention is to pass the address of the pointer to char , ie to pass the address of the variable declared by char * outputbuffer. I want to pass the address of outputbuffer to foo, because I want foo to initialize the pointer with a valid address.
This would be possible only if I pass &outputbuffer to foo instead of outputbuffer itself(outputbuffer is initialized to NULL).

Either

int foo (void * inputbuffer, int sizeofinputbuffer, unsigned char** outputbuffer)

or

int foo (void * inputbuffer, int sizeofinputbuffer, void* outputbuffer)
and perform the appropriate cast inside the function to get to a proper unsigned char**

Hi having void ** worked, I had to typecast the &outputbuffer to void **.
Thanks,
Prashanth

void * is pointer to data of void type.
The size of void is 1(compiler dependent).
memcpy is implemented in some of the compilers such as that of INTEL such that it treats the arguments to be of type void *. Hence it just copies the data byte by byte from one location to the other as the size of void is 1.

void * means it points to any data of any type.
But you can not really dereferece a void * pointer just like that. You need to properly type cast the void pointer and then should be deferenced.
Similarly void** pneeds to be converted to suitable data type for ex int ** k = (int**) p;
And then you can do *k.

all these exercises you may do using char** pointer instead of using void **. It is better to use char ** instead of void **.

Hi having void ** worked, I had to typecast the &outputbuffer to void **.

Maybe so, but that doesn't make it a good idea.

If your function assigns *outputbuffer to something to something that is not a char *, and then main() dereferences it, the result is undefined behaviour.

As you say at the end of the post, it is better to make the argument char **. Then, at least, the compiler can detect if you try to do a suspicious assignment in the function, or pass something incorrectly to it.

This question has already been answered. Start a new discussion instead.