A
Allin Cottrell
I'm reasonably familiar with C pointers, but every now and then I
run into an issue that confuses me. Here is one such.
I have a two-dimensional "array" of doubles, Z, (actually dynamically
allocated). In the function where Z first appears it is declared
as
double **Z;
Now, Z is passed to various function that might have cause to resize
it, so the caller passes &Z, and the callee receives
double ***pZ
OK so far. But sometimes the callee needs to pass to a sub-callee
a subset of Z. For example, Z may "contain" 10 pointers-to-double
but the callee needs to pass to the sub-callee only the last 5 of
these. We can be sure the sub-callee will _not_have to resize the
parent array. My question is, what's the best way of representing,
within callee, the object to be passed to sub-callee?
I have used, e.g.
sub_callee((const double **) &((*pZ)[5]), ...);
This works OK but it looks ugly. Is there a better way?
run into an issue that confuses me. Here is one such.
I have a two-dimensional "array" of doubles, Z, (actually dynamically
allocated). In the function where Z first appears it is declared
as
double **Z;
Now, Z is passed to various function that might have cause to resize
it, so the caller passes &Z, and the callee receives
double ***pZ
OK so far. But sometimes the callee needs to pass to a sub-callee
a subset of Z. For example, Z may "contain" 10 pointers-to-double
but the callee needs to pass to the sub-callee only the last 5 of
these. We can be sure the sub-callee will _not_have to resize the
parent array. My question is, what's the best way of representing,
within callee, the object to be passed to sub-callee?
I have used, e.g.
sub_callee((const double **) &((*pZ)[5]), ...);
This works OK but it looks ugly. Is there a better way?