Being a BASIC/FORTRAN programmer for years, the C/C++ structure is a bit strange to me. I prefer to solve my own problems so I can learn from them. I was having problems accessing array elements and found a document that gave a clear explanation of the use of pointers. It solved my problem, but my initial attempt worked just fine. Here's the first attempt with comments:
const unsigned int mostPermissive [][10] = { { 0, 18, 18, 33, 33, 1, 33, 33, 1, 0}, //0
{ 4, 20, 18, 36, 33, 1, 33, 33, 1, 1376}, //1
...........
const unsigned int nextBlock[][9] = { {0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 3, 4,10, 0, 9, 5, 3, 0},
...........
for (i=0; i<54; i++) //go looking - mostPermissive [0] is lever state
- {*
_ if (leverState == mostPermissive [0]) //found it - mostPermissive column 0 is the lever state_
* { //does this works because it's the first column?*
* for (j=1; j<9; j++) // Set new signal aspects to most permissive*
* {*
_ if (signalAspect[j] != mostPermissive*[j]) //why does this work?
{ //should be != (mostPermissive + j);
signalAspect[j] = mostPermissive[j];
* setBoard[signalBoard[j]] = true;
}
}
break;
I spent a lot of time running in circles because after the above worked, this didn't:
for (i = 1; i<9; i++)
{
signalBlock = nextBlock[switchState]; //signalBlock is the next block for Signal
}
this of course works just fine
for (i = 1; i<9; i++)
{
signalBlock = *(nextBlock[switchState] + i); //signalBlock is the next block for Signal
}*
Can someone explain why the first code worked when it shouldn't?_