| Real-Time Workshop® Embedded Coder™ | ![]() |
| On this page… |
|---|
If your application requires you to replace built-in data type names with user-defined replacement data type names in the generated code, you can do so from the Real-Time Workshop > Data Type Replacement pane of the Configuration Parameters dialog box, shown below in the Model Explorer view.

This pane is available for ERT target based Simulink® models. In addition to providing a mechanism for mapping built-in data types to user-defined replacement data types, this feature:
Performs consistency checks to ensure that your specified data type replacements are consistent with your model's data types.
Allows many-to-one data type replacement, the ability to map multiple built-in data types to one replacement data type in generated code. For example, built-in data types uint8 and boolean could both be replaced in your generated code by a data type U8 that you have previously defined.
Note For limitations that apply, see Data Type Replacement Limitations. |
If you select Replace data type names in the generated code, the Data type names table is displayed:

The table Data type names lists each Simulink built-in data type name along with its Real-Time Workshop® data type name. Selectively fill in fields in the third column with your replacement data types. Each replacement data type should be the name of a Simulink.AliasType object that exists in the base workspace. Replacements may be specified or not for each individual built-in type.
For each replacement data type entered, the BaseType property of the associated Simulink.AliasType object must be consistent with the built-in data type it replaces. For double, single, int32, int16, int8, uint32, uint16, uint8, and boolean, the replacement data type's BaseType must match the built-in data type. For int, uint, and char, the replacement data type's size must match the size displayed for int or char on the Hardware Implementation pane of the Configuration Parameters dialog box. An error occurs if a replacement data type specification is inconsistent.
For example, suppose that you have previously defined the following replacement data types, which exist as Simulink.AliasType objects in the base workspace:
| User-Defined Name | Description |
|---|---|
| FLOAT64 | 64-bit floating point |
| FLOAT32 | 32-bit floating point |
| S32 | 32-bit integer |
| S16 | 16-bit integer |
| S8 | 8-bit integer |
| U32 | Unsigned 32-bit integer |
| U16 | Unsigned 16-bit integer |
| U8 | Unsigned 8-bit integer |
| CHAR | Character data |
You can fill in the Data Type Replacement pane with a one-to-one replacement mapping, as follows:

You can also apply a many-to-one data type replacement mapping. For example, in the following display:
int32 and int are replaced with user type S32
uint32 and uint are replaced with user type U32
uint8 and boolean are replaced with user type U8
Note Many-to-one data type replacement does not support the char (char_T) built-in data type. Use char only in one-to-one data type replacements. |

The user-defined replacement types you specify will appear in your model's generated code in place of the corresponding built-in data types. For example, if you specify user-defined data type FLOAT64 to replace built-in data type real_T (double), then the original generated code shown in Example 3: Generated Code with real_T Built-In Data Type will become the modified generated code shown in Example 4: Generated Code with FLOAT64 Replacement Data Type.
Example 3: Generated Code with real_T Built-In Data Type
...
/* Model initialize function */
void sinwave_initialize(void)
{
...
{real_T *dwork_ptr = (real_T *) &sinwave_DWork.lastSin;
...
}
...Example 4: Generated Code with FLOAT64 Replacement Data Type
...
/* Model initialize function */
void sinwave_initialize(void)
{
...
{FLOAT64 *dwork_ptr = (FLOAT64 *) &sinwave_DWork.lastSin;
...
}
...Data type replacement does not support multiple levels of mapping. Each replacement data type name maps directly to one or more built-in data types.
Data type replacement is not supported for simulation target code generation for referenced models.
Data type replacement is not supported if the GRT compatible call interface option is selected for your model.
Data type replacement occurs during code generation for all .c, .cpp, and .h files generated in build directories (including top and referenced model build directories) and in the _sharedutils directory. Exceptions are as follows:
| rtwtypes.h |
| model_sf.c or .cpp (ERT S-function wrapper) |
| model_dt.h (C header file supporting external mode) |
| model_capi.c or .cpp |
| model_capi.h |
Data type replacement is not supported for complex data types.
Many-to-one data type replacement is not supported for the char built-in data type. Attempting to use char as part of a many-to-one mapping to a user-defined data type introduces a violation of the MISRA-C specification. Specifically, if char (char_T) and either int8 (int8_T) or uint8 (uint8_T) are mapped to the same user replacement type, the result is a MISRA-C violation. Additionally, if you try to generate C++ code, invalid implicit type casts are made and compile-time errors may result. Use char only in one-to-one data type replacements.
![]() | Registering mpt User Object Types | Customizing Data Object Wizard User Packages | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |