I am trying to create a generic function which when called allocated contiguous memory for a dimensional array. Goal is to achieve something like below
so to achieve it - equation I am using is
Type **pArray;
int total_elements = ((rows * cols) + rows);
pArray = (Type **) malloc(total_elements * sizeof(Type));
I am also confused with respect to accessing elements part. I am finding it hard to visualize how below code will fill the elements of above array
for (row = 0; row < dim0; ++row)
{
for (col = 0; col < dim1; ++col)
{
/* For this to work Type must be a 1D array type. */
for (ix = 0; ix < (int)(sizeof(item)/sizeof(item[0])); ++ix)
{
/* printf("%4d\n", testValue); */
ppObj[row][col][ix] = testValue;
if (testValue == SCHAR_MAX)
testValue = SCHAR_MIN;
else
++testValue;
}
}
}
Goal is not to create below array format

