User`s guide
5 Controlling Code Generation
5-18
// interface which dynamically calculates the number of
// outputs based on the number of non-NULL inputs it
// receives. This function processes any input arguments
// and passes them to the implementation version of the
// function, appearing above.
//
V
F
Interface Function
The Compiler produces this interface function only when the M-function uses
the variable
nargout and has at least one output. The void interface function
specifies zero output arguments to the implementation version of the function,
andintheeventthattheimplementationversionstillreturnsanoutput
(which, in MATLAB, would be assigned to the
ans variable), it deallocates the
output.
This is the corresponding
VF interface function (VFoo)forthefoo.m example
described earlier in this chapter. This function calls the
Mfoo function
appearing in
foo.cpp.
//
// The function "Vfoo" contains the void interface for the
// "foo" M-function from file
// "<matlab>\extern\examples\compiler\foo.m" (lines 1-8).
// The void interface is only produced if the M-function
// uses the special variable "nargout", and has at least
// one output. The void interface function specifies zero
// output arguments to the implementation version of the
// function, and in the event that the implementation
mwArray Nfoo(int nargout,
mwArray * b,
mwArray x,
mwArray y) {
mwArray a(mclGetUninitializedArray());
mwArray b__(mclGetUninitializedArray());
a = Mfoo(&b__, nargout, x, y);
if (b != NULL) {
*b = b__;
}
return a;
}
Input argument
processing
Call M-function
Output argument
processing
Input argument
processing