Array Pointer Question

M

Matt

I'm almost embarrassed to ask this because it seems like a complete
newbie question, but here goes.

How do I find out the size of an array of pointers that defines a 2D
matrix called 'matrix0' when the only declaration I can find is
"double **matrix0". After that declaration the next time the matrix is
used is to assign values from:

"matrix0 = stamps[istamp].mat;"

Is its size actually determined by the size of stamps[]?

Kind Regards,

Matt
 
M

Matt

I'm almost embarrassed to ask this because it seems like a complete
newbie question, but here goes.

How do I find out the size of an array of pointers that defines a 2D
matrix called 'matrix0' when the only declaration I can find is
"double **matrix0". After that declaration the next time the matrix is
used is to assign values from:

"matrix0 = stamps[istamp].mat;"

Is its size actually determined by the size of stamps[]?

Kind Regards,

Matt

Actually having just written it out I realised that matrix0 could just
be a variable to temporarily store matrix values. Does that sound
plausible as it would seem like a good explanation for why there is no
size or memory allocated for this 'matrix0'

Kind Regards,

Matt
 
B

Ben Bacarisse

Matt said:
I'm almost embarrassed to ask this because it seems like a complete
newbie question, but here goes.

How do I find out the size of an array of pointers that defines a 2D
matrix called 'matrix0' when the only declaration I can find is
"double **matrix0". After that declaration the next time the matrix is
used is to assign values from:

"matrix0 = stamps[istamp].mat;"

Is its size actually determined by the size of stamps[]?

Kind Regards,

Matt

Actually having just written it out I realised that matrix0 could just
be a variable to temporarily store matrix values. Does that sound
plausible

No. matrix0 will point to the same place as stamps[istamp].mat (this
might be a an array, or it might also be a pointer elsewhere) so
assignments to matrix0[..][..] will not be to anywhere 'temporary'.

To answer your original question, you can't find out the size from the
pointer alone. If the size is important, it will be in stored in the
program somewhere and you need to get it (or calculate it) from that
data. I'd look and the other fields in stamps[istamp] first.
 
M

Matt

Matt said:
I'm almost embarrassed to ask this because it seems like a complete
newbie question, but here goes.
How do I find out the size of an array of pointers that defines a 2D
matrix called 'matrix0' when the only declaration I can find is
"double **matrix0". After that declaration the next time the matrix is
used is to assign values from:
"matrix0 = stamps[istamp].mat;"
Is its size actually determined by the size of stamps[]?
Kind Regards,
Matt
Actually having just written it out I realised that matrix0 could just
be a variable to temporarily store matrix values. Does that sound
plausible

No. matrix0 will point to the same place as stamps[istamp].mat (this
might be a an array, or it might also be a pointer elsewhere) so
assignments to matrix0[..][..] will not be to anywhere 'temporary'.

To answer your original question, you can't find out the size from the
pointer alone. If the size is important, it will be in stored in the
program somewhere and you need to get it (or calculate it) from that
data. I'd look and the other fields in stamps[istamp] first.

stamps.mat is a typedef pointer defined in a separate header file:

typedef struct

{
int x , y;
DATA_TYPE **vectors;
DATA_TYPE *area;
double **mat;
double *scprod;
double sum;
double chi2;
double norm;
double diff;
char keep;
} stamp_struct;


stamp_struct *stamps;

Basically I'm redefining this matrix in GSL form (http://www.gnu.org/
software/gsl/manual/html_node/Matrix-allocation.html) so to define the
matrix I need to state what size matrix0 needs to be. However i can't
find a malloc allocation for stamps.mat any more then I could for
matrix0.

Kind Regards,

Matt
 
C

CBFalconer

Matt said:
.... snip ...

Basically I'm redefining this matrix in GSL form (http://www.gnu.org/
software/gsl/manual/html_node/Matrix-allocation.html) so to define the
matrix I need to state what size matrix0 needs to be. However i can't
find a malloc allocation for stamps.mat any more then I could for
matrix0.

Just run a cross-ref on your source, and then examine the
lines/files indicated under stamps. If it never gets initialized
you have exposed a major flaw. :)
 
M

Matt

Matt wrote:

... snip ...


Just run a cross-ref on your source, and then examine the
lines/files indicated under stamps. If it never gets initialized
you have exposed a major flaw. :)

How would you recommend I do this? I've been trying to use DDD to
debug and show the variables but it's a little fiddly to work with.

Kind Regards,

Matt
 
C

CBFalconer

Matt said:
How would you recommend I do this? I've been trying to use DDD to
debug and show the variables but it's a little fiddly to work with.

Read the docs on your cross-ref utility, or write your own. It's
not hard. What it is is off-topic for this newsgroup.
 

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,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top