I have a statically declared array like this Cell SMatrix_A[36][10]
. When I use SMatrix_A directly in my code (Cell foo = SMatrix_A[12][8]
), everything works fine. However, what I really want is to declare several of these matrices (SMatrix_A, SMatrix_B, etc) and then have a pointer variable switch between them at runtime.
I'm imagining code like this (asusming SMatric_A, B, C are already declared and this is all in the same file scope):
Cell *curMatrix = SMatrix_B;
Cell foo,bar;
...
foo = curMatrix[13][2];
The compiler gives me an: Incompatable pointer types assigning 'Cell*' from 'Cell[36][10]'
on the initial assignment to curMatrix. I thought that referring to an array variable without subscripts was going to give me a pointer type with the value being the first location of the array.
Am I just missing a cast or something?
My previous answer is totally wrong, so I'm giving it another shot!
You need to typedef your 2D array type (this is likely a good idea so that your SMatrix_A, SMatrix_B all have the same size). Then you can create pointers to it as normal. Note that you must dereference the pointer before you index it.