coder.ReplacementTypes
Configuration parameter to specify custom names for MATLAB built-in data types in C/C++ code generation
Description
A coder.ReplacementTypes object contains the configuration
parameters that the code generator uses for creating custom data type names for MATLAB® built-in data types in C/C++ code generation.
You must associate coder.ReplacementTypes object with an Embedded Coder® configuration object (a coder.EmbeddedCodeConfig object) that you pass to
the codegen function.
You can access coder.ReplacementTypes properties from either the
command-line interface (see Specify Custom Names for MATLAB Built-in Data Types) or a dialog box for the associated
configuration object (see Access Replacement Types Properties Through a Dialog Box).
Creation
Use the coder.config function to create a
coder.EmbeddedCodeConfig object for generation of standalone code. When
the coder.config function creates a
coder.EmbeddedCodeConfig object, it sets the
ReplacementTypes property to coder.ReplacementTypes
object.
Properties
Custom name for a double data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a single data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a uint8 data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a uint16 data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a uint32 data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a uint64 data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a int8 data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a int16 data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a int32 data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a int64 data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a char data type in the generated C/C++ code,
specified as a character vector or string scalar.
Custom name for a logical data type in the generated C/C++ code,
specified as a character vector or string scalar.
Enable or disable importing type definitions from external header files for use in the generated C/C++ code.
| Value | Description |
|---|---|
false | This value is the default value. Custom type
definitions are generated in the file |
true | Importing type definitions from external header files is allowed
for code generation. The specified header files are included in
|
External header file names that contain custom type definitions.
To specify a single header file name, you can use a character vector or a string scalar.
To specify multiple header files, use one of the values in this table.
| Value | Description |
|---|---|
| String array | A string array in |
| Cell array of character vectors | A cell array of character vectors in
|
Examples
Write a MATLAB function from which you can generate code. This example uses the function
myAdd.m, which returns the sum of its
inputs.
function c = myAdd(a,b) c = a + b; end
Create a coder.EmbeddedCodeConfig object for generation of a
static
library.
cfg = coder.config('lib','ecoder',true);
Set the EnableCustomReplacementTypes to
true.
cfg.EnableCustomReplacementTypes = true;
Specify custom names for MATLAB built-in data types. For example, in the code, double
is named as Custom_Double and int8 is named as
Custom_Int8.
cfg.ReplacementTypes.double = "Custom_Double"; cfg.ReplacementTypes.int8 = "Custom_Int8";
Generate code by using the codegen function and the
-config
option.
codegen myAdd.m -args {1,int8(1)} -config cfg -report
The generated code contains custom data type names.
Create a writable folder myFiles.
Write a MATLAB function from which you can generate code. Save the function in
myFiles. This example uses the function myAdd.m,
which returns the sum of its
inputs.
function c = myAdd(a,b) c = a + b; end
Write your header file myHeader.h that contains type definitions
for the two inputs of the function myAdd.m. Save it in
myFiles.
#if !defined(MYHEADER) #define MYHEADER typedef double Custom_Double; typedef char Custom_Int8; #endif
Create a coder.EmbeddedCodeConfig object for generation of a
static
library.
cfg = coder.config('lib','ecoder',true);
Specify custom names for MATLAB built-in data types. For example, in the code, double
is named as Custom_Double and int8 is named as
Custom_Int8.
cfg.EnableCustomReplacementTypes = true; cfg.ReplacementTypes.double = "Custom_Double"; cfg.ReplacementTypes.int8 = "Custom_Int8";
Specify configuration properties for importing external header files.
% Include single header file cfg.ReplacementTypes.IsExtern = true; cfg.ReplacementTypes.HeaderFiles = "myHeader.h"; cfg.CustomInclude = 'C:\myFiles'; % Include path of the header file
% Include multiple header files cfg.ReplacementTypes.IsExtern = true; cfg.ReplacementTypes.HeaderFiles = ["myHeader1.h","myHeader2.h","myHeader3.h"] cfg.CustomInclude = '"C:\Program Files\MATLAB\myFiles"'; % Include path of the header files
Generate code by using the codegen function and the
-config
option.
codegen myAdd.m -args {1,int8(1)} -config cfg -report
In the generated code, myAdd_types.h includes the external header
file myHeader.h.
To read more about importing custom data type definitions from external header files, see Import Custom Data Type Definitions from External Header Files (Embedded Coder).
Open the dialog box for the configuration object that refers to the
coder.ReplacementTypes object. For example:
cfg = coder.config('lib'); open('cfg');
In the dialog box, click the Code Appearance tab.
Select Enable custom data type replacement. The Custom Data Type Replacement table lists the name of the supported data types. Specify your custom names for these data types and press Enter.
You can import your own custom type definitions from external header files. Select the Import custom types from external header files check box. In the Header files text field, add the external header file names. For more information, see Import Custom Data Type Definitions from External Header Files (Embedded Coder).
Version History
Introduced in R2019bIf you try to use semicolons in a character vector to separate multiple filenames for
the HeaderFiles property of a coder.ReplacementTypes
object, the code generator produces an error. Use string arrays or cell arrays of character
vectors instead. For example:
Use a string array —
cfg.ReplacementTypes.HeaderFiles = ["myHeader1.h","myHeader2.h","myHeader3.h"]Use a cell array of character vectors —
cfg.ReplacementTypes.HeaderFiles = {'myHeader1.h','myHeader2.h','myHeader3.h'}
Using semicolons in a character vector to separate multiple filenames for the
HeaderFiles property of a coder.ReplacementTypes
object produces a warning and will be removed in a future release. Use string arrays or cell
arrays of character vectors instead. For example:
Use a string array —
cfg.ReplacementTypes.HeaderFiles = ["myHeader1.h","myHeader2.h","myHeader3.h"]Use a cell array of character vectors —
cfg.ReplacementTypes.HeaderFiles = {'myHeader1.h','myHeader2.h','myHeader3.h'}
In a future release, specifying multiple file names, paths, or reserved names in code
configuration objects by using character vectors or string scalars that have delimiters will
be removed. Use string arrays and a cell array of character vector instead. For example, to
include multiple header file names, you can use either a string array in
ReplacementTypes.HeaderFiles as
cfg.ReplacementTypes.HeaderFiles =
["myHeader1.h","myHeader2.h","myHeader3.h"] or a cell array of character vectors
as cfg.ReplacementTypes.HeaderFiles =
{'myHeader1.h','myHeader2.h','myHeader3.h'}.
See Also
Functions
Objects
Topics
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)