From: Jim Rockford on
In creating an array of pointers of the mxArray type, the following
assignments work:


const int n = 10;
mxArray *myarray[n]; // legal



However, the following does not work. In this case, the size of the
mxArray pointer array is given by the field of a structure variable.
This error is probably generic to C/C++ too, by the way.

// Global definition
struct argsForMatlab{
const int nlhs; // number of left hand side arguments
const int nrhs; // number of right hand side arguments
};

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray
*prhs[])
{
argsForMatlab numPlotArgs = {1,10}; // constructor
mxArray *myarray[numPlotArgs.nrhs]; // this assignment is
problematic
// rest of code
}

The errors I get after trying to compile with mex are

>> example.cpp(41) : error C2057: expected constant expression
>> example.cpp(41) : error C2466: cannot allocate an array of constant size 0
>> example.cpp(41) : error C2133: 'myarray' : unknown size



The entire difference here seems to be that the (const int) is
specified explicitly in the first example, which works, and in the
second case the (const int) is extracted from a field of a structure
variable. I was careful to make this field of the (const int) type.

What's the difference? Why does the compiler complain in the second
case but not the first?

Much thanks for any help,
Jim

 | 
Pages: 1
Prev: Hiteczang
Next: PLease help me with mex file