Avoid incompatible pointer warning when dealing with double-indirection

Posted by fnawothnig on Stack Overflow See other posts from Stack Overflow or by fnawothnig
Published on 2010-05-31T13:55:43Z Indexed on 2010/05/31 14:03 UTC
Read the original article Hit count: 202

Assuming this program:

#include <stdio.h>
#include <string.h>

static void ring_pool_alloc(void **p, size_t n) {
    static unsigned char pool[256], i = 0;
    *p = &pool[i];
    i += n;
}

int main(void) {
    char *str;
    ring_pool_alloc(&str, 7);
    strcpy(str, "foobar");
    printf("%s\n", str);
    return 0;   
}

... is it possible to somehow avoid the GCC warning

test.c:12: warning: passing argument 1 of ‘ring_pool_alloc’ from incompatible pointer type
test.c:4: note: expected ‘void **’ but argument is of type ‘char **’

... without casting to (void**) (or simply disabling the compatibility checks)? Because I would very much like to keep compatibility warnings regarding indirection-level...

© Stack Overflow or respective owner

Related posts about c

    Related posts about type-conversion