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
double
— Custom name for double
data type
' ' (default) | character vector | string scalar
Custom name for a double
data type in the generated C/C++ code,
specified as a character vector or string scalar.
single
— Custom name for single
data type
' ' (default) | character vector | string scalar
Custom name for a single
data type in the generated C/C++ code,
specified as a character vector or string scalar.
uint8
— Custom name for uint8
data type
' ' (default) | character vector | string scalar
Custom name for a uint8
data type in the generated C/C++ code,
specified as a character vector or string scalar.
uint16
— Custom name for uint16
data type
' ' (default) | character vector | string scalar
Custom name for a uint16
data type in the generated C/C++ code,
specified as a character vector or string scalar.
uint32
— Custom name for uint32
data type
' ' (default) | character vector | string scalar
Custom name for a uint32
data type in the generated C/C++ code,
specified as a character vector or string scalar.
uint64
— Custom name for uint64
data type
' ' (default) | character vector | string scalar
Custom name for a uint64
data type in the generated C/C++ code,
specified as a character vector or string scalar.
int8
— Custom name for int8
data type
' ' (default) | character vector | string scalar
Custom name for a int8
data type in the generated C/C++ code,
specified as a character vector or string scalar.
int16
— Custom name for int16
data type
' ' (default) | character vector | string scalar
Custom name for a int16
data type in the generated C/C++ code,
specified as a character vector or string scalar.
int32
— Custom name for int32
data type
' ' (default) | character vector | string scalar
Custom name for a int32
data type in the generated C/C++ code,
specified as a character vector or string scalar.
int64
— Custom name for int64
data type
' ' (default) | character vector | string scalar
Custom name for a int64
data type in the generated C/C++ code,
specified as a character vector or string scalar.
char
— Custom name for char
data type
' ' (default) | character vector | string scalar
Custom name for a char
data type in the generated C/C++ code,
specified as a character vector or string scalar.
logical
— Custom name for logical
data type
' ' (default) | character vector | string scalar
Custom name for a logical
data type in the generated C/C++ code,
specified as a character vector or string scalar.
IsExtern
— Import type definition from external header files
false
(default) | true
| logical
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
|
HeaderFiles
— Name of external header file for import
' ' (default) | string array | cell array of character vectors | character vector
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
Specify Custom Names for MATLAB Built-in Data Types
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.
Import Custom Type Definitions from External Header Files
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).
Access Replacement Types Properties Through a Dialog Box
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).
See Specify Configuration Parameters in Command-Line Workflow Interactively.
Version History
Introduced in R2019bR2024a: Using Semicolons to Specify Multiple Header Files in coder.ReplacementTypes
Object has been Removed
If 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'}
R2023b: Using Semicolons to Specify Multiple Header Files in coder.ReplacementTypes
Object Warns
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'}
R2021a: Capability to Specify Multiple Entries in Code Configuration Objects by Using Character Vector Will Be Removed
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
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)