Click here to Skip to main content
15,997,509 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Global arrays do not display properly in a simple forms project. I can set local variables equal to elements of the global array and the values are correct. Scalar variables display properly.

Any ideas? I am using Visual Studio 2010.
C++
//GlobalTest.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace GlobalTest;

double XX[7] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
double ZZ = 3;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{

    double YY[7];

    for(int i=0; i<7; i++)
    {
        YY[i] = XX[i];
    }

    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    // Create the main window and run it
    Application::Run(gcnew Form1());
    return 0;
}
Posted
Updated 11-Sep-10 7:32am
v2
Comments
Sandeep Mewara 11-Sep-10 13:32pm    
Use PRE tags to format code part, it makes the question readable.
hansonrh 11-Sep-10 14:36pm    
Thanks
Richard MacCutchan 12-Sep-10 3:58am    
Maybe if you showed the code that does the actual display of the data someone could offer a suggestion.
hansonrh 12-Sep-10 10:05am    
It is the debugger Watch List that does not display the proper values. The original program was a default Windows Forms solution generated by VS2010. Put a breakpoint at Application::EnableVisualStyles(); And you will see that YY and the scalar ZZ are correct and XX is not. If the declaration for XX is placed within main() all XX has the right values but is not Global.

- XX {Length=7} double[]
[0] 5.8837896832001251e-299 double
[1] 5.8841360114961856e-299 double
[2] 5.8843365173517701e-299 double
[3] 5.8845917066224970e-299 double
[4] 1.6698053231989028e-316 double
[5] 0.00000000000000000 double
[6] 0.00000000000000000 double
ZZ 3.0000000000000000 double
- YY {Length=7} double[]
[0] 0.00000000000000000 double
[1] 1.0000000000000000 double
[2] 2.0000000000000000 double
[3] 3.0000000000000000 double
[4] 4.0000000000000000 double
[5] 5.0000000000000000 double
[6] 6.0000000000000000 double

I tried the declaring the following code prior to main() and got even worse results in the Watch List.


typedef struct {
char Buf[6];
short dim2;
short dim1;
} bufferQ;

bufferQ bufferW[] = {
{"ABCD",1,2},
{"abcd",3,4},
{"EFGH",5,6},
{"efgh",7,8},
{"IJKL",9,19} };
Sandeep Agri 17-Nov-21 12:21pm    
getting the same issue.. did you get the solution?

1 solution

Never had this problem. Are you sure that you do not have a memory error somewhere else in your program? I once took over a program that was written so poorly that the program would break if you changed variable names due to extensive memory errors.
 
Share this answer
 
Comments
Sandeep Agri 17-Nov-21 12:22pm    
if anyone get the solution to this question please reach me out here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900