473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Array Pointer Question

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
6 1501
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: overbored | last post by:
I can do this: int asdf; int* zxcv = asdf; but not this: int asdf; int** zxcv = asdf;
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
9
by: sangeetha | last post by:
Hello, Is there any performance difference in using of the following two declaration? int (*ptr); //Array of 10 int pointers int *ptr; // pointer-to-array of 10. Regards, Sangeetha.
11
by: x-pander | last post by:
given the code: <file: c.c> typedef int quad_t; void w0(int *r, const quad_t *p) { *r = (*p); }
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
51
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
18
by: mdh | last post by:
>From p112 ( K&R). Given an array declared as static char arr= { { 0,1,........},{0,1,.....}}; let arr be passed as an argument to f. f( int (*arr) ) {....} It is noted that the...
2
by: Imran | last post by:
Hello all, I am trying to pass 2D array to a func, as follows, it is showing compiler error. void helloptr(int **a){ a = 0xB; } int main(int argc, char* argv){
9
by: subramanian100in | last post by:
The following portion is from c-faq.com - comp.lang.c FAQ list · Question 6.13 int a1 = {0, 1, 2}; int a2 = {{3, 4, 5}, {6, 7, 8}}; int *ip; /* pointer to int */ int (*ap); /* pointer to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.