Products & Services Solutions Academia Support User Community Company

eml.rref - Pass argument by reference as read-only input

Syntax

[y =] eml.ceval('function_name', eml.rref(argI), ... un)

Arguments

argI

Variable passed by reference as a read-only input to the external C function called in eml.ceval.

Description

[y =] eml.ceval('function_name', eml.rref(argI), ... un) passes the variable argI by reference as a read-only input to the external C function called in eml.ceval. You add eml.rref inside eml.ceval as an argument to function_name. The argument list can contain multiple eml.rref constructs. Add a separate eml.rref construct for each read-only argument that you want to pass by reference to function_name.

Only use eml.rref in Embedded MATLAB code that you have compiled with emlmex or emlc. eml.rref generates an error in uncompiled M-code.

Example

In the following example, an Embedded MATLAB function fcn has a single input u and a single output y. fcn calls a C function foo, passing u by reference as a read-only input. The value of output y is passed to fcn by the C function through its return statement.

Here is the Embedded MATLAB function code:

function y = fcn(u)

y = 0; %Constrain return type to double
y = eml.ceval('foo', eml.rref(u));

The corresponding C function prototype looks like this:

real_T foo(real_T *a)

In this example, Embedded MATLAB infers the type of the input u from its definition in the parent model.

The C function prototype defines the input as a pointer because it is passed by reference.

Embedded MATLAB cannot infer the type of the output y, so you must set it explicitly—in this case to a constant value 0 whose type defaults to double, matching the C type real_T. For a list of type mappings, see Mapping MATLAB Types to C.

See Also

eml.ceval, eml.opaque, eml.ref, eml.wref

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS