Filter löschen
Filter löschen

What can the implicit type of mxGetPr return argument be?

1 Ansicht (letzte 30 Tage)
Peter Cotton
Peter Cotton am 17 Feb. 2011
The following code returns a compiler warning because the pointer retrieved is of incompatible type.
mwSize countDims[2] = {nP,1};
plhs[1] = mxCreateNumericArray(ndim,countDims,mxINT64_CLASS,mxREAL);
int* count;
count = mxGetPr(plhs[1]);
This appears to be the case no matter what integer type I use in mxCreateNumericArray, or whether I use int, short etc.
  1 Kommentar
Peter Cotton
Peter Cotton am 17 Mär. 2011
Small suggestion for Mathworks. It would be nice if the mxGetData help was a little more explicit in regard to what is very much a standard procedure (extracting, casting etc) and alternatives. For example mxGetLogical might appear in the "See Also" for mxGetData. I wonder aloud if specialized mxGet's for integer types would be appreciated by users.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

James Tursa
James Tursa am 17 Feb. 2011
mxGetPr returns a (double *) type and is typically only used for double class variables, although most compilers will let you get away with just a warning if you convert it to another non-(void *) pointer type. Use the mxGetData function (and mxGetImagData for complex variables) for other data types, such as your int64 class variable. mxGetData and mxGetImagData return a (void *) type. You may want to cast the result explicitly. Also, using an int * will almost certainly not give you a 64-bit integer type on a typical compiler these days. You will need to use something else, like long long or int64_t.

Weitere Antworten (1)

Jan
Jan am 18 Feb. 2011

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by