Menu

#638 array needed to be declared globally to work

open
nobody
None
5
2012-09-26
2006-04-15
Anonymous
No

const int TotalRows = 8;
const int wRows[TotalRows][3] = { {0, 1, 2},
{3, 4, 5},
{6, 7, 8},
{0, 3, 6},
{1, 4, 7},
{2, 5, 8},
{0, 4, 8},
{2, 4, 6} };

The version I'm using is 4.9.9.2

This array was copied out of a book on beginning game
programming.
When Referencing this array locally (in the same
function where it is used) for possibly the tenth
time, it overwrote one of the values with a garbage
value (element 2,2 was 1403345) which crashed windows.

In addition to the array being declared as a constant,
nothing in my code attempted to change any of the
values. It was intended to be just that-a Constant.

The same code worked fine in Visual C++ 2005 express
and did not put any garbage values in the array.

I worked around the bug by declaring the array
globally. Also, if you declare the array with the
second dimension 4 instead of 3 it seems more robust.
However, 3 is the proper number, as is easily seen.

Discussion


Log in to post a comment.