coder.ceval
Call C/C++ function from generated code
Syntax
Description
out = coder.ceval(
calls the C/C++ function specified in functionName
,arg1,...,argN
)functionName
from the
generated code. One or more input arguments can be passed to the called C/C++
function within the function call. The called C/C++ function can return a single
scalar output. For example, to call the C standard function
isalnum
with input myChar
and output
isNum
, use isnum =
coder.ceval("isalnum",myChar)
.
Because the type of the output returned by the C/C++ function is not known by
the code generator at code generation time, you must specify the type of
out
(for example, by assigning it a dummy value) before
the coder.ceval
call. Variables to hold nonscalar output can
be passed by reference to the called C/C++ function by using coder.ref
or coder.wref
.
To call C/C++ standard functions, you must specify the header file using
coder.cinclude
or the
"-headerfile"
argument to coder.ceval
.
To call custom C/C++ functions, in addition to specifying the header file, you
must also specify the external source file or library using coder.updateBuildInfo
.
The coder.ceval
function can only be used in the generated
code. Calls to coder.ceval
in MATLAB® execution produce an error. To determine if a MATLAB function is executing in MATLAB, use coder.target
.
out = coder.ceval(
calls the C/C++ function specified in options
,functionName
,arg1,...,argN
)functionName
from the
generated code using the options specified in the options
argument. For example, use "-headerfile"
to specify a C/C++
header file, and use "-global"
to indicate that the called
C/C++ function uses global variables.
Examples
Input Arguments
Limitations
You cannot use
coder.ceval
on functions that you declare as extrinsic by usingcoder.extrinsic
.If a property has a get method, a set method, or validators, or if the property is a System object™ property with an attribute that constrains or modifies the property value, then you cannot pass the property by reference to an external function. See Passing By Reference Not Supported for Some Properties.
Variable-size matrices as entry-point parameters are not supported for row-major code generation.
Tips
To use
coder.ceval
to a call a C/C++ function that accepts or returns types of variables that do not exist in MATLAB code, such as pointers,FILE
types for file I/O, and C/C++ macros, use thecoder.opaque
function.External code called using
coder.ceval
and the generated code run within the same process and share memory. If external code erroneously writes to the memory that contains data structures used by the generated code, it can cause unexpected behavior or a crash. For example, if the external code attempts to write data to an array after its end point, the generated code might behave unexpectedly or crash.MATLAB uses UTF-8 as its system encoding on the Windows® platform. As a result, system calls made from within a generated MEX function accept and return UTF-8-encoded strings. By contrast, the code generated by MATLAB Coder™ encodes text data by using the encoding specified by the Windows locale. So, if your MATLAB entry-point function uses
coder.ceval
to call an external C/C++ function that assumes a different system encoding, then the generated MEX function might produce garbled text. If this happens, you must update the external C/C++ function.To pass MATLAB character vectors to C/C++ functions called using
coder.ceval
, you must explicitly terminate each character vector with a null character (0
). For more information, see Generate C/C++ Strings from MATLAB Strings and Character Row Vectors.
Extended Capabilities
Version History
Introduced in R2011aSee Also
coder.ref
| coder.rref
| coder.wref
| coder.target
| codegen
| coder.extrinsic
| coder.opaque
| coder.columnMajor
| coder.rowMajor
| coder.updateBuildInfo