MATLAB: Do I get a “referenced memory” error during MEX compilation with MATLAB 7.9 (R2009b)

MATLAB

I am getting the following error message in a popup Windows box while running MEX on my C source files:
The instruction at "0x00412e7d" referenced memory at "0x00000000". The memory could not be "read".
Click on OK to terminate the program
Click on CANCEL to debug the program
The same code compiles fine with the Microsoft Visual Studio C/C++ compiler.

Best Answer

This can occur if your C source code contains typedef statements with more than 2 tokens/words after the typedef declaration. One example of this is:
typedef unsigned __int32 BOOL32;
This statement is supported by the Microsoft C compiler but not LCC.
To fix this problem, either remove these types of typedef statements, or install the Microsoft C compiler. If you do not want to pay for the Microsoft C compiler, Microsoft does offer an "Express Edition" compiler free of charge that is available for download at