M
mt
I am trying to understand the following code and I am having some
problems..
1. What is the meaning of double*** pdata? Why the need to declare a
pointer to a pointer to a pointer?
2. same thing for int*** pmask
Please elucidate this for me.
static int
makedatamask(int nrows, int ncols, double*** pdata, int*** pmask)
{ int i;
double** data;
int** mask;
data = malloc(nrows*sizeof(double*));
if(!data) return 0;
mask = malloc(nrows*sizeof(int*));
if(!mask)
{ free(data);
return 0;
}
for (i = 0; i < nrows; i++)
{ data = malloc(ncols*sizeof(double));
if(!data) break;
mask = malloc(ncols*sizeof(int));
if(!mask)
{ free(data);
break;
}
}
if (i==nrows) /* break not encountered */
{ *pdata = data;
*pmask = mask;
return 1;
}
*pdata = NULL;
*pmask = NULL;
nrows = i;
for (i = 0; i < nrows; i++)
{ free(data);
free(mask);
}
free(data);
free(mask);
return 0;
}
problems..
1. What is the meaning of double*** pdata? Why the need to declare a
pointer to a pointer to a pointer?
2. same thing for int*** pmask
Please elucidate this for me.
static int
makedatamask(int nrows, int ncols, double*** pdata, int*** pmask)
{ int i;
double** data;
int** mask;
data = malloc(nrows*sizeof(double*));
if(!data) return 0;
mask = malloc(nrows*sizeof(int*));
if(!mask)
{ free(data);
return 0;
}
for (i = 0; i < nrows; i++)
{ data = malloc(ncols*sizeof(double));
if(!data) break;
mask = malloc(ncols*sizeof(int));
if(!mask)
{ free(data);
break;
}
}
if (i==nrows) /* break not encountered */
{ *pdata = data;
*pmask = mask;
return 1;
}
*pdata = NULL;
*pmask = NULL;
nrows = i;
for (i = 0; i < nrows; i++)
{ free(data);
free(mask);
}
free(data);
free(mask);
return 0;
}