MATLAB: Do I get the error “C2440: cannot convert from ‘void *’ to ‘ *’ ” when I use mxCalloc

casterrorexplicitMATLABmxcalloc

When trying to compile my MATLAB API application I get the following error message:
error C2440 : cannot convert from 'void *' to 'char *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast

Best Answer

The MATLAB API mxCalloc routine returns a void pointer and requires an explicit cast to the desired output type. Therefore, you will need to do something such as the following:
char *g;
g = (char *) mxCalloc(20, sizeof(char));
For an explanation of "void*" and when it is used in C/C++ programming, refer to a book on programming in C/C++.
Related Question