473,513 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Similar topics

13
26986
by: simondex | last post by:
Hi, Everyone! Does anyone know how to initialize an int array with a non-zero number? Thank You Very Much. Truly Yours, Simon Dexter
8
2359
by: ehames | last post by:
Hi guys, As far as I know, for any type T, and positive integer N, if I have an array declared as: T array; then, &array and array are the same element. Is there any reason why a
3
1423
by: Arkady Frenkel | last post by:
Hi, guys! Is it possible to write byte array, I receive already from one stream to another, but not from first element, without copy part of array to new one. I mean I have byte array and need to...
33
8143
by: Zytan | last post by:
I want to make a zero element array. I know that Nothing is not the same as a zero element array, since I can't get the length of, or iterate through, an array = Nothing. I could make a zero...
10
6260
by: Chris Forone | last post by:
Hello Group, there is some memberfunc for std::valarray to return a pointer to the first element in the array. How do i use this? Thanx a lot. HAND Chris
7
1677
by: Szabolcs Borsanyi | last post by:
I know that this topic has been discussed a lot, still I'd appreciate a clear cut (and correct) answer: I pass a multidimensional array to a function, which is defined as int f(int a) { int...
6
7647
by: CSharper | last post by:
I am trying to use the following; I have an array with bunch of values in it. I am trying to find a value that contains part of the string I am passing eg string array = {"help","Csharp rocks"} ...
4
4553
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
0
7160
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
7384
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,...
1
7099
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
7525
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...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.