1

I modified the following code

void aligned_free(void *p) {
    free(((void**) p)[-1]);
}

to

void aligned_free(void **p) {
    free((p)[-1]);
}

with function call

char* a = (char*)aligned_malloc(10000,64);
aligned_free(a);

and the compiler gives the error "cannot convert from char* to void**". Why the pointer char* cannot be converted to void**, but void* is OK?

Tony
  • 83
  • 7
  • 2
    Because `void **` is a pointer to a pointer, and `char *` (or `void *`) is just a pointer – Jcl Dec 13 '14 at 23:12
  • 1
    The important distinction is that `void **` points to something different than `char *` does. `void *` is a generic point, but `void **` is not. `void *` can point to anything. `void **` must point to a `void *`. – William Pursell Dec 13 '14 at 23:22
  • I wonder what made you want to remove the cast in the first place? – kuroi neko Dec 13 '14 at 23:26

1 Answers1

5

void * is a generic pointer. An object of type void * can point to anything. A void **, however, can only point to an object of type void *. A char is not a void *, so the conversion fails.

William Pursell
  • 204,365
  • 48
  • 270
  • 300