Why do I get the error "C2440: cannot convert from 'void *' to '<type> *' " when I use mxCalloc?

17 views (last 30 days)
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

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Jan 2011
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++.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!