Building Mex file error?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
K M Ibrahim Khalilullah
el 27 de Sept. de 2017
Editada: Walter Roberson
el 28 de Sept. de 2017
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 comentarios
Rik
el 27 de Sept. de 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
el 28 de Sept. de 2017
Editada: K M Ibrahim Khalilullah
el 28 de Sept. de 2017
Respuesta aceptada
Walter Roberson
el 28 de Sept. de 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 comentarios
Walter Roberson
el 28 de Sept. de 2017
Editada: Walter Roberson
el 28 de Sept. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!