User`s manual

Troubleshooting
1-37
Run MATLAB within a debugging environment. This process is already
described in the chapters on creating C and Fortran MEX-files, respectively.
Problem 5 - Program Generates Incorrect Results
If your program generates the wrong answer(s), there are several possible
causes. First, there could be an error in the computational logic. Second, the
program could be reading from an uninitialized section of memory. For
example, reading the 11th element of a 10-element vector yields unpredictable
results.
Another possibility for generating a wrong answer could be overwriting valid
data due to memory mishandling. For example, writing to the 15th element of
a 10-element vector might overwrite data in the adjacent variable in memory.
This case can be handled in a similar manner as segmentation violations as
described in Problem 4.
In all of these cases, you can use
mexPrintf to examine data values at
intermediate stages, or run MATLAB within a debugger to exploit all the tools
the debugger provides.
Compiler and Platform-Specific Issues
This section refers to situations specific to particular compilers and platforms.
MEX-Files Created in Watcom IDE
If you use the Watcom IDE to create MEX-files and get unresolved references
to API functions when linking against our libraries, check the argument
passing convention. The Watcom IDE uses a default switch that passes
parameters in registers. MATLAB requires that you pass parameters on the
stack.
Memory Management Compatibility Issues
To address performance issues, we have made some changes to the internal
MATLAB memory management model. These changes will allow us to provide
future enhancements to the MEX-file API.
As of MATLAB 5.2, MATLAB implicitly calls
mxDestroyArray, the mxArray
destructor, at the end of a MEX-file’s execution on any
mxArrays that are not
returned in the left-hand side list (
plhs[]). You are now warned if MATLAB
detects any misconstructed or improperly destructed
mxArrays.