By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Array Pointer Question

P: n/a
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

Aug 8 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Aug 8, 12:09 pm, Matt <matt...@hotmail.comwrote:
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

Aug 8 '07 #2

P: n/a
Matt <ma*****@hotmail.comwrites:
On Aug 8, 12:09 pm, Matt <matt...@hotmail.comwrote:
>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.

--
Ben.
Aug 8 '07 #3

P: n/a
On Aug 8, 2:22 pm, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
Matt <matt...@hotmail.comwrites:
On Aug 8, 12:09 pm, Matt <matt...@hotmail.comwrote:
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.

--
Ben.
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

Aug 8 '07 #4

P: n/a
Matt wrote:
>
.... 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. :-)

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Aug 8 '07 #5

P: n/a
On Aug 8, 4:01 pm, CBFalconer <cbfalco...@yahoo.comwrote:
Matt wrote:

... 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. :-)

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account fromhttp://www.teranews.com
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
Aug 8 '07 #6

P: n/a
Matt wrote:
CBFalconer <cbfalco...@yahoo.comwrote:
>Matt wrote:

... snip ...
>>Basically I'm redefining this matrix in GSL form
(http://www.gnu.org/software/gsl/manu...llocation.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. :-)

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.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Aug 9 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.