I get the doubt having the following function that asks for a double pointer:
#include <stdlib.h>
void prueba(void **ap)
{
*ap = NULL;
}
with the following main:
#include <stdlib.h>
#include <stdio.h>
void prueba(void **ap);
int main(void)
{
char *str;
str = (char *)malloc(sizeof(char) * 5);
prueba(&str);
if (str == NULL)
printf("NULL");
return (0);
}
When compiling, gcc takes out the following warning:
main2.c:11:9: warning: incompatible pointer types passing 'char **' to parameter of type 'void **' [-Wincompatible-pointer-types]
prueba(&str);
^~~~
main2.c:4:23: note: passing argument to parameter 'ap' here
void prueba(void **ap);
The doubt comes from that with simple pointers this does not happen, for example, with the following function and main respectively gcc compiles correctly, despite passing a pointer to char to a function that asks for a pointer void:
function:
#include <stdlib.h>
void prueba(void *ap)
{
ap = NULL;
}
main:
#include <stdlib.h>
#include <stdio.h>
void prueba(void *ap);
int main(void)
{
char *str;
str = (char *)malloc(sizeof(char) * 5);
prueba(str);
if (str == NULL)
printf("NULL");
return (0);
}
Why should it be possible with simple pointers but with double ones?