Building Mex file error?

3 次查看(过去 30 天)
I going to build mex file, but it give these error:
warning C4244: '=' : conversion from '__int64' to 'long', possible loss of data
error C2440: '=' : cannot convert from 'size_t *' to 'int *'
Maybe compiler version problem. But, how can I solve it?
  2 个评论
Rik
Rik 2017-9-27
Are you certain there is no bug in the code?
What compiler are you using, what Matlab release and what is your OS?
K M Ibrahim Khalilullah
编辑:K M Ibrahim Khalilullah 2017-9-28
Thank for your comment.
  1. MEX configured to use 'Microsoft Windows SDK 7.1 (C++)' for C++ language compilation.
  2. matlab 2015b.
  3. Windows 10 (OS)

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-9-28
warning C4244: '=' : conversion from '__int64' to 'long', possible loss of data
That is a correct warning. Not all compilers treat "long" as a 64 bit number. You might be lucky with any given compiler, but your code would break on other compilers. You would be advised to change the code to use long long instead of long. C99 and later promise that long long is at least 64 bits.
error C2440: '=' : cannot convert from 'size_t *' to 'int *'
I am positive that would be an error in C++. I would need to research to see if it is a definitely an error in C. But in either C or C++, the circumstances under which it would be possible to convert between a size_t and an int (that is, after dereferencing the pointer) would be (considering that you are using a 64 bit type) that you are using a DSP that has only 64 bit integers and no smaller integer data type (other than perhaps 8 bit bytes), which would be a really rare DSP !!
When I search I see that error C2440 for Microsoft compilers is this type conversion error only for C++. For C, C2440 is a different error. This tends to suggest that you are compiling with C++ compiler, not with a C compiler.
Either way, the code is broken. If the purpose of the code is to handle generic pointers, passing around pointer to "something" through multiple layers that do not have to care what kind of data it is pointing to, until finally in that line of code it needs to convert back from generic pointer to int* specifically: if that is what is happening, then the generic pointers must be made into void* rather than size_t*.
C will automatically allow conversion of void* pointers to any other pointer type, but C++ requires an explicit cast operation.
If the purpose of the code is to pass a pointer to an integer value, then you have the problem that size_t and int are different widths on probably every CPU or DSP in existence. (Though I would need to closely re-read the standards against the hypothesis that a 16 bit CPU with 16 bit size_t could be conformant.)
  3 个评论
Walter Roberson
Walter Roberson 2017-9-28
编辑:Walter Roberson 2017-9-28
mxGetJc does not return a pointer to the beginning of a vector of int: it returns a pointer to the beginning of a vector of mwIndex
K M Ibrahim Khalilullah
Thanks. it's OK now. But you give the answer indirectly!!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Troubleshooting in MATLAB Compiler SDK 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by