Computer: MacBook Aluminum Unibody (2 Ghz Intel Core 2 Duo), Running 10.6.2
Software: Xcode 3.2, trying 10.5 SDK, 10.6 SDK, release and debug modes. Also (separately) Qt Creator 1.3.1 (based on Qt 4.6.1 32 bit).
I am writing a simple C++ command-line utility program that counts paths through a 3D lattice of points (starting with the 2x2x2 case, but written to work for NxNxN). My program seems pretty simplistic (it only defines integers & integer arrays and does stuff with them - no strings or floats or file reading/writing). I am running into various (likely related) problems. OF these, problems (2) and (3) bother me the most...
(Problem 1) In general, I get significantly different results if I compile & run my program in debug vs. release mode. I have read an overview of the differences between debug & release, but I am too much of a novice to figure out what is going on.
(Problem 2) Instead of going through the debugger, I sometimes insert output such as {cerr << "The value of N is " << N << endl;}. I get this strange happening: adding such a line of output will sometimes significantly affect seemingly unrelated results when running the program. That is, I can run my program and get "Answer = 15", but with a line of output in a benevolent spot can change this to "Answer = 13" after I rebuild & run again. This is mind boggling to me.
(Problem 3) In my program, I define an integer array check[N+3][N+3][N+3] (which is check[5][5][5] for now, since N=2). The check array is initialized to hold all 0's, and entries are changed to and from 0 and 1 along the way (with a while loop). I get an unexpected change of variable at one point, and I have no idea how it is happening - a snippet of the code and the terminal output from running the program is given below...
Here is the code snippet:
Here is the corresponding output in the terminal:
I have stepped through the part of the program in the debugger and check[1][1][1] mysteriously changes from 0 to 1.
Any help or comments would be appreciated -- thanks.
Software: Xcode 3.2, trying 10.5 SDK, 10.6 SDK, release and debug modes. Also (separately) Qt Creator 1.3.1 (based on Qt 4.6.1 32 bit).
I am writing a simple C++ command-line utility program that counts paths through a 3D lattice of points (starting with the 2x2x2 case, but written to work for NxNxN). My program seems pretty simplistic (it only defines integers & integer arrays and does stuff with them - no strings or floats or file reading/writing). I am running into various (likely related) problems. OF these, problems (2) and (3) bother me the most...
(Problem 1) In general, I get significantly different results if I compile & run my program in debug vs. release mode. I have read an overview of the differences between debug & release, but I am too much of a novice to figure out what is going on.
(Problem 2) Instead of going through the debugger, I sometimes insert output such as {cerr << "The value of N is " << N << endl;}. I get this strange happening: adding such a line of output will sometimes significantly affect seemingly unrelated results when running the program. That is, I can run my program and get "Answer = 15", but with a line of output in a benevolent spot can change this to "Answer = 13" after I rebuild & run again. This is mind boggling to me.
(Problem 3) In my program, I define an integer array check[N+3][N+3][N+3] (which is check[5][5][5] for now, since N=2). The check array is initialized to hold all 0's, and entries are changed to and from 0 and 1 along the way (with a while loop). I get an unexpected change of variable at one point, and I have no idea how it is happening - a snippet of the code and the terminal output from running the program is given below...
Here is the code snippet:
Code:
...
if(X == start1 && Y == start2 && Z == start3)
{
check[start1][start2][start3] = 0;
cout << "output1: check[1][1][1] = " << check[1][1][1] << endl;
}
...
// the code here does not redefine or call the check array
// the check array is not mentioned what-so-ever
...
cout << "output2: check[1][1][1] = " << check[1][1][1] << endl;
...
Here is the corresponding output in the terminal:
Code:
...
output1: check[1][1][1] = 0
output2: check[1][1][1] = 1
...
I have stepped through the part of the program in the debugger and check[1][1][1] mysteriously changes from 0 to 1.
Any help or comments would be appreciated -- thanks.