Customize Data Type Replacement
While generating C/C++ code from MATLAB® code, the Data Type Replacement option enables you to use
built-in C data types or MathWorks® typedefs in the generated code. Code generation supports these data types for
custom renaming: double
, single
,
uint8
, uint16
, uint32
,
uint64
, int8
, int16
,
int32
, int64
, char
, and
logical
.
The Data Type Replacement option is available in the Generate Code window (More Settings), on the Code Appearance tab. You can select one of these options:
Use built-in C data types in the generated code
Use MathWorks typedefs in the generated code
Note
The code generator does not replace variable-size character arrays with
char*
type strings in the generated code.
If you have Embedded Coder® installed, you can
specify custom names for MATLAB built-in data types in the generated C/C++ code. For example, you can customize
double
as Custom_Double
.
Specify Custom Data Type Names by Using the MATLAB Coder App
To specify custom names for the MATLAB data types:
Open the MATLAB Coder™ app.
Navigate to the Generate Code step.
Click More Settings.
In the Code Appearance tab, select Enable custom data type replacement under Custom Data Type Replacement.
The table lists the name of the supported data types. Specify your custom names for these data types and press Enter. The specified custom names replace the built-in data type names in the generated code. If you do not specify a custom name, the code generator uses a default name.
Specify Custom Data Type Names by Using the Command-Line Interface
Use the EnableCustomReplacementTypes
and
ReplacementTypes
properties in an Embedded Coder configuration object when you generate code by using
codegen
.
Write a MATLAB function from which you can generate code. This example uses the function
myAdd
that returns the sum of its inputs.function c = myAdd(a,b) c = a + b; end
Create a code configuration object for generation of a static library.
cfg = coder.config('lib','ecoder',true);
Set the
EnableCustomReplacementTypes
property totrue
.cfg.EnableCustomReplacementTypes = true;
Specify custom name for the data types. Here, the built-in data type name
uint8
is customized toCustom_Uint8
.cfg.ReplacementTypes.uint8 = "Custom_Uint8";
Generate code by using
codegen
and-config
option.codegen myAdd.m -args {1,uint8(1)} -config cfg -report