For debugging Matlab-MEX, which can be quite a hassle, it would be nice to have better assertion capabilities. Following this question about mex-assertions, it is possible to define a preprocessor makro, that throws an error to Matlab and prints a string (can mostly replace mxAssert, which unfortunately crashes Matlab2011b).
#define myassert( isOK,astr )      ( (isOK) ? (void)0 : (void) mexErrMsgTxt(astr) ) 
It would be much nicer to print the file, line number and caller function, from where following example assertion myassert(A=B,"A not B") is raised! This answer to the initial question states that they are the preprocessor variables:
__LINE__,__PRETTY_FUNCTION__, __FILE__
How can we print these preprocessor variables with mexErrMsgTxt?
The problem is, that mexErrMsgTxt() takes a char* argument and not multiple inputs like for example printf(const char *format, ...).
My thinking goes only so far at the moment:
- It's not possible to build a function, because the preprocessor variables will have the values (e.g. line number) from the function.
- It was not possible for me to write a working multiline preprocessor makro that creates a charfrom the passedstring astrand passes it tomexErrMsgTxt(). Maybe a solution is along these lines.
- A hybrid solution with a char creating preprocessor makro and a function that passes it to mexErrMsgTxt()doesn't feel like good coding practice.
It would be really nice to make the specified error string optional.
 
     
    