View double* as array of double? 
Author Message
 View double* as array of double?

MS DevStudio 97, VC++ 5

This elementary de{*filter*} operation has *got* to be in here somewhere, but
I can't seem to find it. Can anyone tell me the magic
command/menu/keystroke?

I have a pointer (lets say to type double) the de{*filter*} correctly shows me
the value pointed to, but the de{*filter*} is unaware that it is merely the
first of many values in an array! (I'm viewing the guts of a container
type class)

How do I view the array of doubles instead of just the first one?
I can't find anything on this in the online help files.

--
Tim Gogolin
Software Engineer, Stat-Ease, Inc.



Wed, 19 Jan 2000 03:00:00 GMT  
 View double* as array of double?

Quote:

>I have a pointer (lets say to type double) the de{*filter*} correctly shows me
>the value pointed to, but the de{*filter*} is unaware that it is merely the
>first of many values in an array! (I'm viewing the guts of a container
>type class)

>How do I view the array of doubles instead of just the first one?
>I can't find anything on this in the online help files.

Isn't this normal behaviour, a pointer to char only shows the first
byte as well.

There are two work arounds, the first in the de{*filter*}, the second in
code :

double_var[0]
double_var[1]  up to
double_var[n]  show you all you want;

In code :

#define NBR_OF_DOUBLES 17

int func(double * ptr)          // actually an array
{
        double arr[NBR_OF_DOUBLES];

        memcpy(arr, ptr, sizeof(arr));

Quote:
}

Now the de{*filter*} can show you the values of all doubles in arr.

Since a pointer is syntactically the same as an array, the de{*filter*}
can't see the difference. So you have to show it, don't you?



Thu, 20 Jan 2000 03:00:00 GMT  
 View double* as array of double?

Quote:

> MS DevStudio 97, VC++ 5
> I have a pointer (lets say to type double) the de{*filter*} correctly shows me
> the value pointed to, but the de{*filter*} is unaware that it is merely the
> first of many values in an array! (I'm viewing the guts of a container
> type class)

The problem here is that a double* is not the same thing as a
double[].  That's just C.

For builtin types, it's easy.  Just open up the memory window and
point to that address.  You can switch it to view memory as doubles,
either in the context menu or in Tools.Options.Debug

For user defined types, it's a little tougher.  One option is to
create an actual array:

void func (Foo foo*, unigned len) {

#ifdef DEBUG
        Foo foo_copy[1000];
        memcpy (foo_copy, foo, sizeof (Foo, len);
#endif

Quote:
}

--



Thu, 20 Jan 2000 03:00:00 GMT  
 View double* as array of double?


Quote:

> >How do I view the array of doubles instead of just the first one?
> >I can't find anything on this in the online help files.
> Since a pointer is syntactically the same as an array, the de{*filter*}
> can't see the difference. So you have to show it, don't you?

Ooh, I get to pick nits!

Sorry, they're not the same.  Try:

// file1.cpp

extern int *p;

int main () {
        p = 3;

        return 0;

Quote:
}

// file2.cpp

int p[100];

It won't work.

--



Thu, 20 Jan 2000 03:00:00 GMT  
 View double* as array of double?

Use the same syntax as you would in a program.

e.g. double *pDouble;

then in the de{*filter*} watch window
        *(pDouble + n) where n is the element you want.



Quote:
> I have a pointer (lets say to type double) the de{*filter*} correctly shows
me
> the value pointed to, but the de{*filter*} is unaware that it is merely the
> first of many values in an array!

> How do I view the array of doubles instead of just the first one?



Fri, 21 Jan 2000 03:00:00 GMT  
 View double* as array of double?


Quote:


> >I have a pointer (lets say to type double) the de{*filter*} correctly shows me
> >the value pointed to, but the de{*filter*} is unaware that it is merely the
> >first of many values in an array! (I'm viewing the guts of a container
> >type class)

> >How do I view the array of doubles instead of just the first one?
> >I can't find anything on this in the online help files.

> Isn't this normal behaviour, a pointer to char only shows the first
> byte as well.

> There are two work arounds, the first in the de{*filter*}, the second in
> code :

> double_var[0]
> double_var[1]  up to
> double_var[n]  show you all you want;

> In code :

> #define NBR_OF_DOUBLES 17

> int func(double * ptr)          // actually an array
> {
>         double arr[NBR_OF_DOUBLES];

>         memcpy(arr, ptr, sizeof(arr));
> }

> Now the de{*filter*} can show you the values of all doubles in arr.

> Since a pointer is syntactically the same as an array, the de{*filter*}
> can't see the difference. So you have to show it, don't you?

I'm sorry, this still seems kinda weak from a debugging point of view...
(memcpy ?!)
Yes I know that a pointer to double is not *exactly* the same as an array
of double,
but its damn close, and is seems like such an obvious thing to want to view
(viewing the entire array, not just one at a time via *(ptr+n) syntax.)

I guess I'm just spoiled by Metrowerks de{*filter*} (Mac version, I can't
speak for their PC offerings), which offers a "Open Array Window" menu
command when an array or a pointer is the current selection.

--
Tim Gogolin
Software Engineer, Stat-Ease, Inc.



Sun, 23 Jan 2000 03:00:00 GMT  
 View double* as array of double?

Quote:

>I'm sorry, this still seems kinda weak from a debugging point of view...
>(memcpy ?!)
>Yes I know that a pointer to double is not *exactly* the same as an array
>of double,
>but its damn close, and is seems like such an obvious thing to want to view
>(viewing the entire array, not just one at a time via *(ptr+n) syntax.)

>I guess I'm just spoiled by Metrowerks de{*filter*} (Mac version, I can't
>speak for their PC offerings), which offers a "Open Array Window" menu
>command when an array or a pointer is the current selection.

I don't say you're wrong, I just say the de{*filter*} can't see the
difference between an array and a pointer, and since he (the de{*filter*})
can not thru trial and error look ahead to all the (perhaps double)
pointers to see what's coming, you'd have to help him.

Most hardware does not like to interprete any pointer as one to a
double; we must be aware of that, don't we???

Wim



Mon, 24 Jan 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. result of double*double is no double

2. can long double be less precise than double?

3. Problem with Double.IsNan() and Double.Nan

4. epsilon for float, double long double

5. Difference between double and long double?

6. Converting long double to double

7. double != double best way [Q]

8. 80bit double from mac to 64bit double to pc

9. Internal structure of long double and double

10. diff between double and long double

11. Double Double

12. Comparing double NAN with double INF is not IEEE compliant

 

 
Powered by phpBB® Forum Software