I have a question regarding void* and void** , and I know this is kind of an old question and has been asked (somewhat) earlier in stackoverflow. So the question is:
When I compile this code with gcc 4.4.3 under ubuntu 10.10, I get the following warning:
zz.c: In function 'main': zz.c:21: warning: passing argument 1 of 'bar' from incompatible pointer type zz.c:9: note: expected 'void **' but argument is of type 'float **'
why it is ok to pass the variable x as an argument to foo (), but it fails to pass the variable y as an argument to bar (). I can fix this by explicitly translating both variables into void* and void** , as expected.
void foo (void* a){ } void bar(void **a){ *a = (float *) malloc(100*sizeof(float)); } int main (){ float *x = (float*) malloc(100*sizeof(float)); foo(x); free(x); float *y; bar(&y); free(y); return 0; }
source share