My question is related to this one but I did not find an answer there. The reason you may want to use void** is just to avoid an excess of typecasting or is there another one? I ask this because I guess you can always use a void* as a void** but I could be missing something else. Just to test if it was like this, I wrote these lines:
#include "stdio.h"
#include "stdlib.h"
void **a;
void *b;
int MyFunction(int a)
{
return 1;
}
int MyFunction_2(int a)
{
return 2;
}
typedef int (function_pointer)(int);
void main(void)
{
b = malloc(2 * sizeof(void*));
*((void**) b) = MyFunction;
*((void**) b + 1) = MyFunction_2;
a = (void**) malloc(2 * sizeof(void*));
*a = MyFunction;
*(a + 1) = MyFunction_2;
printf("Result = %d\n", ((function_pointer *) *((void**) b))(1));
printf("Result = %d\n", ((function_pointer *) *((void**) b + 1))(1));
printf("Result = %d\n", ((function_pointer *) *a)(1));
printf("Result = %d\n", ((function_pointer *) *(a + 1))(1));
}
It compiles without any warning and the output is (as I expected):
Result = 1
Result = 2
Result = 1
Result = 2
Edit
I feel like you misunderstood the question. It is not about the code I am showing, I do not care how wrong it is and I do not think it is fine in any aspect, I would never use something like that (it was hard to make it work, actually). My doubt was related to why or in what conditions void** could or should be used since in every example I can think of, I could just use a void*. The only reason I can think about is avoiding typecasting. Is there anything else?