I am getting a warning as follows on 64 bit system:
warning: cast to pointer from integer of different size
when I make the following call:
char** str;
str = (char **)Calloc2D(nObj + 1, 20, sizeof(char))
Here is the actual function to allocate 2D array:
void **Calloc2D(size_t nobj1, size_t nobj2, size_t size)
{
void **p1;
void *p2;
size_t iobj1;
char *c2;
/* Allocate memory for one big array */
p2 = calloc((nobj1 * nobj2), size);
if (p2 == NULL) return NULL;
/* Allocate memory for the first dimension */
p1 = (void **) calloc(nobj1, sizeof(void *));
if (p1 == NULL) {
free(p2);
return NULL;
}
/* Set up the pointers for the first dimesion */
c2 = (char *) p2;
for (iobj1 = 0; iobj1 < nobj1; iobj1++) {
p1[iobj1] = (void *) c2;
c2 += (nobj2 * size);
}
/* Return a pointer to the 2-dimensional array */
return p1;
}
What I do not understand is why I am getting the above warning thought my function has been fully declared to return void**. My understanding is that in 64 bit systems void**
and char**
should have the same size (8 bytes). Then why this warning and how to fix it.