views:

164

answers:

2

I have a function like this:

MyFunction(double matrix[4][4])
{/*do stuff*/}

I am calling this from an outer function (the otuer function is a member function of a class, in case that matters):

OuterFunction()
{
double[4][4] x;
initialize(x); //this function puts the data I want in the matrix
MyFunction(x);
}

I am trying to debug this progaram using the Visual Studio debugger. The problem is that when I am looking at the locals for the OuterFunction, I can see all the elements of the array just fine, but when I am looking at the locals for MyFunction, I can only see the first row of the array, and it says it's a matrix[4]* rather than a matrix[4][4]. This even happens when I am only passing a one dimensional array - I pass in a matrix[4], then the debugger identifies it as a matrix* and only lets me see the first element of the array. Is it possible to fix this so I can see all of the array in the debugger?

A: 

It is can be solved by using a vector of vectors, or having your matrix variable in the watch windows like "matrix,4". The ",4" is a format that tells the debugger show 4 elements.

leiz
A: 

When you pass the matrix[][] to the function then you are actually only passing a pointer matrix**. The C code in the function has no idea of what the size of the matrix is and so neither does the debugger.

To use the function or general marticies you will have to pass the dimensions to the function.

You can see later values of say matrix* in the debugger by asking for *(matrix + n).

But you are using C++ not C so much easier to use C++ things like std::vector (If doing C++ you very rarely declare arrays to be passed around)

Mark