Main Content


Create C++ function entry based on specified parameters and register in code replacement table



entry = registerCPPFunctionEntry(hTable,priority,numInputs,functionName,inputType,implementationName,outputType,headerFile,genCallback,genFileName,nameSpace) provides a quick way to create and register a code replacement C++ function entry.

This function can be used only if your C++ function entry meets the following conditions:

  • The input arguments are of the same type.

  • The input argument names and the return argument name follow the default Simulink® naming convention:

    • For input argument names, u1, u2, ..., un

    • For return argument, y1

When you register a code replacement library containing C++ function entries, you must specify the value {'C++'} for the LanguageConstraint property of the library registry entry. For more information, see Register Code Replacement Library.


collapse all

This example shows how to use the registerCPPFunctionEntry function to create a C++ function entry for sin in a code replacement table.

hLib = RTW.TflTable;

hLib.registerCPPFunctionEntry(100, 1, 'sin', 'single', 'sin', ...
                              'single', 'cmath', '', '', 'std');

Input Arguments

collapse all

The hTable is a handle to a code replacement table previously returned by hTable = RTW.TflTable.

Example: hLib

The priority specifies the search priority for the function entry, relative to other entries of the same function name and conceptual argument list within this table. Highest priority is 0, and lowest priority is 100. If the table provides two implementations for a function, the implementation with the higher priority shadows the one with the lower priority.

Example: 100

Example: 1

The functionName specifies the name of the function to replace. The name must match a function listed in Code You Can Replace from MATLAB Code or Code You Can Replace From Simulink Models.

Example: 'sin'

This function requires that the input arguments are of the same type.

Example: 'double'

The implementationName specifies the name of the implementation. For example, if functionName is 'sqrt', implementationName can be 'sqrt' or a different name.

Example: 'sqrt'

Example: 'double'

Example: '<math.h>'

The genCallback specifies a callback that follows code generation. If you specify 'RTW.copyFileToBuildDir', and if this function entry is matched and used, the code generator calls function RTW.copyFileToBuildDir after code generation. This callback function copies additional header, source, or object files that you have specified for this function entry to the build folder.

Example: ''

This argument is reserved for MathWorks developers.

Example: ''

The nameSpace specifies the C++ namespace in which the implementation function is defined. If this function entry is matched, the software emits the namespace in the generated function code (for example, std::sin(tfl_cpp_U.In1)). If you specify '', the software does not emit a namespace designation in the generated code.

Example: 'std'

Output Arguments

collapse all

The entry is a handle to the created C++ function entry. Specifying the return argument in the registerCPPFunctionEntry function call is optional.

Version History

Introduced in R2010a