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

Only First Element of Array Displaying in Debugger, others are zero

P: n/a
Hi all,

I have a dynamically allocated array of doubles in VC++ .NET. When I
view the array in the watch window with "arrayName, 10", it displays
the correct value for arrayName[0], but arrayName[1] through
arrayName[9] are all zeros. Note that arrayName is actually double*,
and not double[].

When I print out the array to the screen using printf, the correct
(non-zero) values are displayed. I'd rather not dump a bunch of
printf's everywhere to debug this, however. I know I am not violating
any array bounds and the memory is getting allocated.

This is actually the same issue as:
http://groups.google.com/group/micro...19616a37f14c66

There were no replies and hoped that re-posting this would help.

Thanks!
--J

May 5 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
> I have a dynamically allocated array of doubles in VC++ .NET. When I
view the array in the watch window with "arrayName, 10", it displays
the correct value for arrayName[0], but arrayName[1] through
arrayName[9] are all zeros. Note that arrayName is actually double*,
and not double[].

When I print out the array to the screen using printf, the correct
(non-zero) values are displayed. I'd rather not dump a bunch of
printf's everywhere to debug this, however. I know I am not violating
any array bounds and the memory is getting allocated.

This is actually the same issue as:
http://groups.google.com/group/micro...19616a37f14c66

There were no replies and hoped that re-posting this would help.


Hi,

the watch windows doesn't care if you declared it as an array or a pointer.
if I do this:
double *arr = new double[10];
*arr = 10;
arr[9] = 9;

and then type arr, 10 in the watch window, I get an array of 10 values, of
which only the first and last one have a normal value.
what type of program are you debugging: native or mixed mode?

could you perhaps show us a fragment of code that reproduces your problem?

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
May 6 '06 #2

P: n/a
<Ja*************@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi all,

I have a dynamically allocated array of doubles in VC++ .NET. When I
view the array in the watch window with "arrayName, 10", it displays
the correct value for arrayName[0], but arrayName[1] through
arrayName[9] are all zeros. Note that arrayName is actually double*,
and not double[].

When I print out the array to the screen using printf, the correct
(non-zero) values are displayed. I'd rather not dump a bunch of
printf's everywhere to debug this, however. I know I am not violating
any array bounds and the memory is getting allocated.

This is actually the same issue as:
http://groups.google.com/group/micro...19616a37f14c66

There were no replies and hoped that re-posting this would help.

Thanks!
--J


If you have just a pointer to the first element of an array you can use a
special construct in the watch window.

Assume your pointer's variable name is p. To regard this as a pointer to an
array of 10 elements, just write "p, 10" instead of just "p" in your watch
window.

Marcus
May 6 '06 #3

P: n/a
Hi Bruno,

I have it set to auto right now. But the problem is present for
Managed Only and Mixed. It won't even hit my breakpoints when set to
Native Only.

I am using an open source package called OpenCV. It's from Intel and
is for image processing.

Anyways, I am looking at a struct defined in OpenCV with the following
form (only the relevant portions of the struct are shown):

struct
{
...
union
{
uchar* ptr;
short* s;
int* i;
float* fl;
double* db;
} data;
...
} CvMat;

// Create a 4x5 matrix with 64bit precision
// Sorting through the OpenCV code, this initializes the
// data union via malloc()
// The CV_64FC1 flag lets OpenCV know to use the
// db variable in the data union
CvMat *mat_ptr = cvCreateMat(4,5,CV_64FC1);

for( int i = 0; i < 4; i++ )
{
for( int j = 0; j < 5; j++ )
{
printf( "%lf\n", (mat_ptr->data.db)[i*4+j];
}
}

So the bottom line is that when all is said and done, I want to view
the contents of:
mat_ptr->data.db, which is a double* pointing to the beginning of a
block of data sized to fit the 20 elements in the matrix of type
double.

Let's say the output from the printf's is:
35.5234234
45.2334556
3.4657667
....
4.565731

But when I try to view the contents in the watch window during a
breakpoint, I get the following (trying to show the watch window in
ASCII...):

mat_ptr->data.db, 20
|
|- [0] 35.5234234
|- [1] 0.0
|- [2] 0.0
....
|- [19] 0.0

Hope this is a bit more explicit and gives you something more to work
with.

Thanks!
Jared

May 8 '06 #4

P: n/a
In reference to my previous post:

Assume there is code between the allocation of data and the display to
initalize the array to the necessary values. I failed to put that in
the example code, but the array IS getting initalized.

Thanks!
Jared

May 8 '06 #5

P: n/a
A co-worker of mine was also debugging this problem. He resolved the
issue by just creating a new project and using as many defaults as
possible. My plan is to look through the settings of the projects and
try to determine which setting(s) was(were) the root of the problem.

We were having issues with ATL/MFC linking before, so we may have made
some settings changes that made this to be a problem.

I'll post something up here if I am able to figure out the culprit for
future reference to anyone else who may be having this problem.

Thanks for the input you gave!!

Regards,
Jared

May 8 '06 #6

P: n/a
OK well I lucked out and the problem was from one of the first settings
I tried.

Under the the Project Properties, General, Use Managed Extensions was
set to "Yes", Changing it to "No" fixed the array display error. I
honestly do not know what this setting does, or why it would affect the
output of the debugger, but the problem is fixed.

Anyone know why this setting was the culprit?

Thanks!
Jared

May 8 '06 #7

P: n/a
OK well I lucked out and the problem was from one of the first settings
I tried.

Under the the Project Properties, General, Use Managed Extensions was
set to "Yes", Changing it to "No" fixed the array display error. I
honestly do not know what this setting does, or why it would affect the
output of the debugger, but the problem is fixed.

Anyone know why this setting was the culprit?

Thanks!
Jared

May 8 '06 #8

P: n/a
> OK well I lucked out and the problem was from one of the first settings
I tried.

Under the the Project Properties, General, Use Managed Extensions was
set to "Yes", Changing it to "No" fixed the array display error. I
honestly do not know what this setting does, or why it would affect the
output of the debugger, but the problem is fixed.

Anyone know why this setting was the culprit?


when you compile with managed extensions, you create an executable that uses
the .NET framework.
you can mix regular C++ code and .NET code into 1 exe for example. great for
code reuse.

I cannot say for sure why you have the problem you have, but there have been
a few reports on this newsgroup that the watch window does not display the
correct values for some arrays if the code is mixed mode. (.NET and native).

if you could reproduce the problem with a small demo project, you can submit
a bug report to
http://lab.msdn.microsoft.com/produc...k/default.aspx
then post the link back here so that others can validate the report and vote
for it.
--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
May 8 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.