Getting error while converting C MEX-file into pure c++
i am converting some C mex-files into pure C++. obviously i need to convert mxarrays and mex functions.
as you see in the code, it creates an mxarray at line 60,
mxArray *mxGradient = mxCreateNumericArray(3, out, mxDOUBLE_CLASS, mxREAL);
and at the line 61 assigns it to a pointer with mxgetpr,
double *gradient = (double *)mxGetPr(mxGradient);
at the line 68 it sums the pointer with multiplication of integers,
double *tempGradientVBase = gradient + ( out[0] * out[1]);
i couldn't manage to understand the line 68. what does it means?
开发者_如何学Goi don't know so much about mxarrays and mex files. could anyone please help me?
This is C pointer arithmetic.
The code that you pasted is treating gradient
as a pointer to the first double
in an array of double
s. By gradient + ( out[0] * out[1] )
, it means "give me the pointer to the double
at index out[0] * out[1]
in the array of double
s beginning at gradient
". It is equivalent to &gradient[ out[0] * out[1] ]
.
精彩评论