Identifier Format Control
You can customize generated identifiers by using identifier naming rules. An identifier
naming rule consists of a macro that contains a combination of literal text, tokens, and token
decorators. The code generator replaces the tokens in the macro with certain text values
depending on the type of token. For example, use the $R
token to insert the
root model name into an identifier. For information about how to modify the expanded values,
see Modify Identifier Format Tokens by Using Token Decorators.
Use identifier naming rules to generate identifiers that are unique, space-efficient, and compliant with your coding standards. You can set model-wide default identifier naming rules by using model configuration parameters. To set default naming rules for certain types of data elements, use the Embedded Coder® Dictionary. To override default naming rules for individual modeling elements, use the Code Mappings editor. Different identifier naming rules support different sets of tokens.
Literal text that you include in an identifier naming rule must contain only characters
that are valid in C and C++ identifiers (a-z
, A-Z
,
_
, and 0-9
). If you place multiple tokens
consecutively in an identifier naming rule, the code generator inserts the underscore
(_
) character between each pair of expanded tokens, even if a token
expands to an empty value. You cannot use the same token multiple times in one identifier
naming rule.
The code generator prioritizes tokens in the order shown in the Identifier Format Tokens table. Tokens that are listed earlier in the table are higher priority than those that are listed later. If the generated identifier exceeds the value of the Maximum identifier length model configuration parameter, the code generator truncates tokens from lowest priority to highest priority until the length does not exceed the configuration parameter value.
Identifier Format Tokens
Token | Description |
---|---|
$C | Expands to a checksum to avoid naming collisions for shared utilities. For
shared utilities that you do not generate from a MATLAB Function block,
This token is available only for the Shared utilities identifier format model configuration parameter. Use the Shared checksum length model configuration parameter to set the length of the checksum. |
$M | Expands to name-mangling text. The code generator generates name-mangling text to avoid naming collisions in generated identifiers. By default, the code generator generates name-mangling text that is as short as possible without introducing naming collisions and omits the name-mangling text if there are no collisions. You can specify a minimum length for the name-mangling text by using the Minimum mangle length model configuration parameter. For more information, see Avoid Identifier Naming Collisions. |
$U | Expands to custom text that you specify in the Custom token text model configuration parameter. |
$F | Expands to the name of a subsystem method. For example, when the code
generator generates an update method identifier, This token is available only for the Subsystem methods model configuration parameter. |
$N | Expands to text derived from the name of the Simulink® object for which the code generator is generating an identifier.
Identifier naming rules in the model configuration parameters can produce text for
the You can configure the length of the expansion of the
|
$R | Expands to the name of the root model. To avoid naming collisions, this
token is required if you use referenced models. If the root model name contains
characters that are not valid in C or C++ identifiers, the code generator replaces
those characters with underscores ( For more information, see Avoid Identifier Naming Collisions Between Referenced Models. |
$H | For root-level blocks, this token expands to Available for only the Subsystem methods and Field name of global types model configuration parameters. |
$A | Expands to an abbreviation that corresponds to the data type of the
generated variable. For example, for an integer, This token is available only for the Local block output variables, Local temporary variables, and Field name of global types model configuration parameters. |
$I | Expands to a string that represents the input/output type of a subsystem method argument.
This token is available only for the Subsystem method arguments model configuration parameter. |
$G | This token expands differently in different identifier naming rules. For data items, this token expands to the name of the name of the storage class of the data item. For the Header File naming rule of a storage class in the Embedded Coder Dictionary, this token expands to the name of the storage class. For service interface naming rules in the Embedded Coder Dictionary, this token expands to the name of the service. |
$E | Expands to one of these tags that describes the type of a generated file:
This token is available for only the Header files and Source files model configuration parameters. |
$X | Expands to the name of the entry-point callable function that encloses a service function call. This token is available only for sender, receiver, data transfer, and timer service function naming rules in the Embedded Coder Dictionary. |
The $N
and $R
tokens are available in the Pre Statement
and Post Statement
Embedded Coder Dictionary properties, but those properties do not otherwise apply
identifier format control rules.
Identifier Naming Rules by Identifier Type
This table lists types of identifiers that you can configure by using identifier naming rules. Some types of identifiers are configurable from multiple identifier naming rules in different places. The Naming Rule column lists each location that contains a naming rule that modifies the identifier type. To set model-wide default naming rules, use identifier naming rules in the model configuration parameters. To set default naming rules for certain types of data elements, use naming rules in the Embedded Coder Dictionary.
To override naming rules for individual modeling elements, use the Code Mappings editor. For function mappings, the Code Mappings editor interprets Function Name, GetFunction, and SetFunction properties as identifier naming rules and supports token expansion. These properties are listed in the table. For data mappings, the Code Mappings editor interprets each Identifier property as plain text. These properties are not listed in the table.
For identifier naming rules that support the $R
token, that token is
required for models that use model referencing. For identifier naming rules that support the
$N
token, the table lists the value that the code generator uses when
expanding that token.
The model configuration parameter identifier naming rules are available for only
ERT-based targets. Non-ERT-based targets such as GRT implicitly use a default value of
$R$N$M
for those parameters. The model configuration parameter
identifier naming rules do not affect objects that have a storage class other than
Auto
.
Identifier Type | Naming Rule | Default Value | Required Tokens | Other Supported Tokens | Resolution of $N | Notes |
---|---|---|---|---|---|---|
Global variable | Global variables model configuration parameter | $R$N$M | $M | $N , $R , $U | Text derived from the data item that the global variable is associated with, such as a signal name | |
Global type | Global types model configuration parameter | $N$R$M_T | $M | $N , $R , $U | Text derived from the name of the Simulink data type | |
Field name of global type | Field name of global types model configuration parameter | $N$M | $M | $A , $H , $N ,
$U | Text derived from the name of the data item that the field is associated with | |
Subsystem method | Subsystem methods model configuration parameter | $R$N$M$F | $M | $F , $H , $N ,
$R , $U | Text derived from the name of the subsystem | |
Subsystem method argument | Subsystem method arguments model configuration parameter | rt$I$N$M | $M | $I , $N , $U | Text derived from the names of the subsystem and subsystem port | |
Local temporary variable | Local temporary variables model configuration parameter | $N$M | $M | $A , $N , $R ,
$U | Text derived from the data item that the variable is associated with, such as a signal name | |
Local block output variable | Local block output variables model configuration parameter | rtb_$N$M | $M | $A , $N , $U | Text derived from the name of block | |
Constant macro | Constant macros model configuration parameter | $R$N$M | $M | $N , $R , $U | Text derived from the data item that the constant macro is associated with, such as a block name | You can also configure constant macros by using the Generate scalar inlined parameters as model configuration parameter. |
Header file | Header files model configuration parameter | $R$E | $E | $R , $U | None | Cannot consist of exactly Must not include
|
Header File property in Embedded Coder Dictionary, under Memory > Storage Class | $N.h | $N or $R | $G , $U | Model or subsystem that the data is associated with | Must end with If Data
Scope is set to | |
Header File property in data interface Embedded Coder Dictionary, under Functions > Function Customization Template | None | None | $N , $R , $U | Name of the function | ||
Header File Name property in Embedded Coder Dictionary, under General | None | None | $R , $U | None | ||
Source file | Source files model configuration parameter | $R$E | $E | $R , $U | None | Cannot consist of exactly Must not include
|
Definition File property in Embedded Coder Dictionary, under Memory > Storage Class | $N.c | None | $G , $N , $R ,
$U | Model or subsystem that the data is associated with | Must end with .c or .cpp . | |
Definition File property in data interface Embedded Coder Dictionary, under Functions > Function Customization Template | None | None | $N , $R , $U | Name of the function | ||
Data file | Data files model configuration parameter | $R_data | None | $R , $U | None | |
Initialize/Terminate function | Function Naming Rule property in service interface Embedded Coder Dictionary, under Execution > Initialize and Terminate Functions | $R$N | None | $M , $N , $R ,
$U |
| |
Function Naming Rule property in service interface Embedded Coder Dictionary, under Internal > Subcomponent Initialize and Terminate Functions (since R2024a) | $R$N | None | $M , $N , $R ,
$U | |||
Function Name property in Code Mappings editor Functions tab | None | None | $M , $N , $R ,
$U | This property does not support regular expression token decorators. | ||
Periodic/aperiodic function | Function Naming Rule property in service interface Embedded Coder Dictionary, under Execution > Periodic and Aperiodic Functions | $R$N | None | $M , $N , $R ,
$U |
| |
Function Naming Rule property in service interface Embedded Coder Dictionary, under Internal > Subcomponent Periodic and Aperiodic Functions (since R2024a) | $R$N | None | $M , $N , $R ,
$U | |||
Function Name property in Code Mappings editor Functions tab | None | None | $M , $N , $R ,
$U | This property does not support regular expression token decorators. | ||
Receiver service interface function | Function Naming Rule property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Receiver | get_$X$N | $N | $G , $M , $R ,
$U , $X | Inport block name | |
Sender service interface function | Function Naming Rule for Value property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Sender | set_$X$N | $N | $G , $M , $R ,
$U , $X | Outport block name | |
Function Naming Rule for Value by Reference property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Sender | getref_$X$N | $N | $G , $M , $R ,
$U , $X | Outport block name | ||
Data transfer service interface function | Receiver Function Naming Rule property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Transfer | get_$X$N | $N | $M , $R , $X | Data transfer signal name, such as
DataTransferAt | |
Sender Function Naming Rule parameter in service interface Embedded Coder Dictionary, under Service Interfaces > Data Transfer | set_$X$N | $N | $M , $R , $X | Data transfer signal name, such as
DataTransferAt | ||
Shared utility function | Function Naming Rule property in service interface Embedded Coder Dictionary, under Internal > Shared Utility Functions | $N$C | $C | $N , $R , $U | Name of the function | |
Type name | Type Name property in Embedded Coder Dictionary, under Memory > Storage Class | $R$N$G$M | None | $G , $M , $N ,
$R ,$U | Model or subsystem that the data is associated with | This property is visible only if you set the Storage
Type property to Structured . |
Instance name | Instance Name property in Embedded Coder Dictionary, under Memory > Storage Class | $G$N$M | None | $G , $M , $N ,
$R ,$U | Model or subsystem that the data is associated with | This property is visible only if you set the Storage
Type property to Structured . |
Getter function | Name of Getter property in Embedded Coder Dictionary, under Memory > Storage Class | get_$N$M | $N | $M , $R , $U | Associated data element | This property is visible only if you set the Data
Access property to Function , and the
Allowed
Access property to Read/Write or
Read-only . |
GetFunction property in the Code Mappings Editor Property Inspector | get_$N | None | $N | This property is visible only for a data element that has the
This property does not support regular expression token decorators. For more information, see Access Data Through Functions with Storage Class GetSet. | ||
Setter function | Name of Setter property in Embedded Coder, under Memory > Storage Class | set_$N$M | $N | $M , $R , $U | Associated data element | This property is visible only if you set the Data
Access property to Function , the Access
Mode property to Value , and the Allowed
Access property to Read/Write or
Write-only . |
SetFunction property in the Code Mappings Editor Property Inspector | set_$N | None | $N | This property is visible only for a data element that has the
This property does not support regular expression token decorators. For more information, see Access Data Through Functions with Storage Class GetSet. |
Limitations
These generated identifiers do not fully comply with the setting of the Maximum identifier length parameter:
Model methods
Local functions and local variables generated by S-functions or by products such as DSP System Toolbox™ that rely on S-functions
DW
identifiers generated by S-functions in referenced modelsFixed-point shared utility macros and shared utility functions
Simulink
rtm
macrosHeader guard macros
Generated
typedef
statements for global data typesGenerated identifiers for a simulation target such as RSim