#include "mex.h" #include class crash { public: crash() { std::cerr <<"will crash now" << std::endl; static int *ptr=0; // this assignment will cause a segmentation fault *ptr=2; } }; // static variable will be initialised when loading the mex file static crash crashit; // some dummy function which we will never execute void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) { int * p = NULL; }