question on pointer notation

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?
 
R

Russell Hanneken

Allin said:
sub_callee((const double **) &((*pZ)[5]), ...);

This works OK but it looks ugly. Is there a better way?

This should work:

sub_callee((const double **) *pZ + 5, ...);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top