Using the C Math Library | ![]() ![]() |
How Function-Functions Use mlfFeval( )
A function-function uses mlfFeval()
to execute the function passed to it. For instance, mlfOde23()
in Example - Passing Functions As Arguments (ex4.c) calls mlfFeval()
to execute the function lorenz()
. The function-function passes the name of the function to be executed to mlfFeval()
along with the arguments required by the function. In this example, the string array containing "lorenz"
is passed to mlfFeval()
along with the other arguments that were passed to mlfOde23()
.
Because the functions passed to mlfFeval()
take different numbers of input and output arguments, mlfFeval()
uses a non-standard calling convention. Instead of listing each argument explicitly, mlfFeval()
works with arrays of input and output arguments, allowing it to handle every possible combination of input and output arguments on its own.
The prototype for mlfFeval()
is
mxArray *mlfFeval(mlfVarargoutList *varargout,
void (*mxfn)(int nlhs, mxArray **plhs,
int nrhs, mxArray **prhs),
...);
Each function-function, therefore, constructs an array of input arguments (prhs
) and an array of output arguments (plhs
), and then passes those two arrays, along with the number of arguments in each array (nrhs
and nlhs
) and the name of the function (name
), to mlfFeval()
, which executes the function.
![]() | Passing Functions As Arguments to Library Routines | How mlfFeval() Works | ![]() |