I'm creating a 2D square matrix in Excel VBA
Dim Matrix(0 To Nrows, 0 To Ncols) as double
and then I pass it as argument ByRef to a function library,
My_foo(Matrix(0,0))
which calls a C++ code. In C++ code I want to access the matrix to get values and make other operations. On this purpose, I read these values as 1D array, so I created an index [R*Ncols + C], where R and C are the element position in 2D representation
void _stdcall My_foo(double* M, long Nrows, long Ncols){
double Value;
R = 10;
C = 0;
Value = M[R*Ncols + C];
}
At this point I expect to find the element having position (10,0), but I find the element (0,10). It seems my matrix is stored with an inverted column/rows order.
It would be enough to set an index like [C*Nrows + R], and access it by column. I tried this and it works, but it contradicts many blogs and posts...
Why? Is it normal?