Building Mex file error?

3 views (last 30 days)
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 Comments
Rik
Rik on 27 Sep 2017
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 on 28 Sep 2017
Edited: K M Ibrahim Khalilullah on 28 Sep 2017
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)

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Sep 2017
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 Comments
Walter Roberson
Walter Roberson on 28 Sep 2017
Edited: Walter Roberson on 28 Sep 2017
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
K M Ibrahim Khalilullah on 28 Sep 2017
Thanks. it's OK now. But you give the answer indirectly!!

Sign in to comment.

More Answers (0)

Categories

Find more on Troubleshooting in MATLAB Compiler SDK in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!