[quote name='BCullis' timestamp='1350405737' post='4990791']
[quote name='Youbar' timestamp='1350359411' post='4990604']
int x, y = map[x][y];
I'm really curious what happens here. x is declared as an int without being defined, and y is declared as an int defined as map[x][y]...that's a recursive definition on top of an undefined index? It's been a while since I mucked with C++.
I guess it doesn't matter since x and y are unused after their first assignment in main. But I don't see how that's being resolved by the compiler.
[/quote]
Unless I am missing something, the array is improperly populated.
Both X and Y are declared as NULL
After MAIN they are both declared as map[2][2], which are both NULL
Also as it's written the values of X,Y will not update when the map is updated.
Corrected 2D array declaration.
int map[5][5] =
{
{1, 1, 1, 1, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 1, 1, 1, 1}
};
[/quote]
Actually, you can populate a 2D array that way. Both are functionally equivalent.
I am rather surprised that the code does compile though... there is a lot going on there that would require good knowledge of the spec to figure out what would happen.
Interesting lines are the aforementioned:
int x, y = map[x][y];
Which my brain is strugging to grok. I am kinda surprised that compiles. I believed C++ evaluated right to left, so it would encounter the y and x indexes that are undeclared.
The other fun line is:
while (mapn < 5, mapn2 < 5)
Which if my understand of C++ is correct, actually evaluates to
while(mapn2 < 5)
In that it would evaluate the first expression, throw it away, then evaluate the second expression as the condition of the loop.