comparison examples/myfeval.c @ 18367:d1e16bdb3958 stable

myfeval.c: Fix segfault in mex example code. * myfeval.c: Correctly cast away const attribute of prhs[]. Also, add code to work with Octave's built-in 'ans' variable. * external.txi: Update example in External Code Interface for myfeval.
author Rik <rik@octave.org>
date Fri, 24 Jan 2014 09:09:48 -0800
parents 224e76250443
children
comparison
equal deleted inserted replaced
18364:2e62b1f01bfe 18367:d1e16bdb3958
4 mexFunction (int nlhs, mxArray* plhs[], 4 mexFunction (int nlhs, mxArray* plhs[],
5 int nrhs, const mxArray* prhs[]) 5 int nrhs, const mxArray* prhs[])
6 { 6 {
7 char *str; 7 char *str;
8 8
9 mexPrintf ("Hello, World!\n"); 9 mexPrintf ("Starting file myfeval.mex\n");
10 10
11 mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs); 11 mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs);
12 12
13 if (nrhs < 1 || ! mxIsString (prhs[0])) 13 if (nrhs < 1 || ! mxIsString (prhs[0]))
14 mexErrMsgTxt ("ARG1 must be a function name"); 14 mexErrMsgTxt ("ARG1 must be a function name");
15 15
16 str = mxArrayToString (prhs[0]); 16 str = mxArrayToString (prhs[0]);
17 17
18 mexPrintf ("I'm going to call the function %s\n", str); 18 mexPrintf ("I'm going to call the function %s\n", str);
19 19
20 mexCallMATLAB (nlhs, plhs, nrhs-1, (mxArray*)prhs+1, str); 20 if (nlhs == 0)
21 nlhs = 1; // Octave's automatic 'ans' variable
22
23 /* Cast prhs just to get rid of 'const' qualifier and stop compile warning */
24 mexCallMATLAB (nlhs, plhs, nrhs-1, (mxArray**)prhs+1, str);
21 25
22 mxFree (str); 26 mxFree (str);
23 } 27 }