Main Content

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. You can use token decorators to modify the expanded values of tokens.

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 in the 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. If the generated identifier exceeds the value of the Maximum identifier length model configuration parameter, the code generator first truncates the token that is lowest in the table.

Identifier Format Tokens

TokenDescription
$C

Available for only the Shared utilities identifier format model configuration parameter. For shared utilities that you generate from a MATLAB Function block, the code generator expands the $C token to a checksum to avoid naming collisions. For other shared utilities, the code generator expands to a checksum only if the identifier naming rule does not contain $N or the generated identifier length exceeds the value of the Maximum identifier length 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

Available only for the Subsystem methods model configuration parameter. Expands to the method name. For example, when the code generator generates an update method identifier, it expands the $F token to Update. For Stateflow® functions, this token expands to an empty value.

$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 use hidden logic when expanding the $N token and might produce text that does not correspond directly to visible text in Simulink.

You can configure the length of the expansion of the $N token by using the System-generated identifiers model configuration parameter.

$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

Available for only the Subsystem methods and Field name of global types model configuration parameters. For root-level blocks, this token expands to root. For subsystem-level blocks, this token expands to sN, where N is a unique system number. For Stateflow

functions, this token expands to an empty value.
$A

Available for only the Local block output variables, Local temporary variables, and Field name of global types model configuration parameters. This token expands to an acronym that corresponds to the data type of the generated variable. For example, for an integer, the code generator expands the $A token to i32.

$I

Available for only the Subsystem method arguments model configuration parameter. This token expands to a string that represents the input/output type of the argument.

  • Insert u if the argument is an input.

  • Insert y if the argument is an output.

  • Insert uy if the argument is an input and output.

$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

Available for only the Header files and Source files model configuration parameters. This token expands to one of these tags that describes the type of file:

  • capi

  • capi_host

  • dt

  • testinterface

  • private

  • types

$X

Available only for sender, receiver, data transfer, and timer service function naming rules in the Embedded Coder Dictionary. This token expands to the name of the entry-point callable function that encloses the service function call.

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, user 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 TypeNaming RuleDefault ValueRequired TokensOther Supported TokensResolution of $NNotes
Global variableGlobal variables model configuration parameter$R$N$M$M$N, $R, $UText derived from the data item with which the global variable is associated, such as a signal name 
Global typeGlobal types model configuration parameter$N$R$M_T$M$N, $R, $UText derived from the name of the Simulink data type 
Field name of global typeField name of global types model configuration parameter$N$M$M$A, $H, $N, $UText derived from the name of the data item with which the field is associated 
Subsystem methodSubsystem methods model configuration parameter$R$N$M$F$M$F, $H, $N, $R, $UText derived from the name of the subsystem 
Subsystem method argumentSubsystem method arguments model configuration parameterrt$I$N$M$M$I, $N, $UText derived from the names of the subsystem and subsystem port 
Local temporary variableLocal temporary variables model configuration parameter$N$M$M$A, $N, $R, $UText derived from the data item with which the variable is associated, such as a signal name 
Local block output variableLocal block output variables model configuration parameterrtb_$N$M$M$A, $N, $UText derived from the name of block 
Constant macroConstant macros model configuration parameter$R$N$M$M$N, $R, $UText derived from the data item with which the constant macro is associated, such as a block nameYou can also configure constant macros by using the Generate scalar inlined parameters as model configuration parameter.
Header fileHeader files model configuration parameter$R$E$E$R, $UNone

Cannot consist of exactly $E; must contain literal text, another token, or a token decorator.

Must not include .h or .hpp.

Header File property in Embedded Coder Dictionary, under Memory > Storage Class$N.h$N or $R$G, $UModel or subsystem with which the data is associatedMust end with .h or .hpp.
Header File property in data interface Embedded Coder Dictionary, under Functions > Function Customization TemplateNoneNone$N, $R, $UName of the function 
Header File Name property in Embedded Coder Dictionary, under GeneralNoneNone$R, $UNone 
Source fileSource files model configuration parameter$R$E$E$R, $UNone

Cannot consist of exactly $E; must contain literal text, another token, or a token decorator.

Must not include .c or .cpp.

Definition File property in Embedded Coder Dictionary, under Memory > Storage Class$N.cNone$G, $N, $R, $UModel or subsystem with which the data is associatedMust end with .c or .cpp.
Definition File property in data interface Embedded Coder Dictionary, under Functions > Function Customization TemplateNoneNone$N, $R, $UName of the function 
Data fileData files model configuration parameter$R_dataNone$R, $UNone 
Initialize/Terminate functionFunction Naming Rule property in service interface Embedded Coder Dictionary, under Execution > Initialize and Terminate Functions$R$NNone$M, $N, $R, $U
  • initialize for the initialization function of the component model.

  • terminate for the termination function of the component model.

 
Function Naming Rule property in service interface Embedded Coder Dictionary, under Internal > Subcomponent Initialize and Terminate Functions (since R2024a)$R$NNone$M, $N, $R, $U 
Function Name property in Code Mappings Editor Functions tabNoneNone$M, $N, $R, $UThis property does not support regular expression token decorators.
Periodic/aperiodic functionFunction Naming Rule property in service interface Embedded Coder Dictionary, under Execution > Periodic and Aperiodic Functions$R$NNone$M, $N, $R, $U
  • For periodic functions of the component model, step if there is only one periodic function, or step0, step1, step2, … if there are multiple. The code generator produces these functions if you select the Single output/update function model configuration parameter.

  • For update functions of the component model, update if there is only one update function, or update0, update1, update2, … if there are multiple. The code generator produces these functions if you clear the Single output/update function model configuration parameter.

  • For output functions of the component model, output if there is only one output function, or output0, output1, output2, … if there are multiple. The code generator produces these functions if you clear the Single output/update function model configuration parameter.

  • For aperiodic functions of the component model, text derived from the control signal name or function-call Inport block name.

  • For the reset function of the component model, the value of the Event name parameter of the Event Listener block inside the Reset Function block.

 
Function Naming Rule property in service interface Embedded Coder Dictionary, under Internal > Subcomponent Periodic and Aperiodic Functions (since R2024a)$R$NNone$M, $N, $R, $U 
Function Name property in Code Mappings Editor Functions tabNoneNone$M, $N, $R, $UThis property does not support regular expression token decorators.
Receiver service interface functionFunction Naming Rule property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Receiver get_$X$N$N$G, $M, $R, $U, $XInport block name 
Sender service interface functionFunction Naming Rule for Value property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Senderset_$X$N$N$G, $M, $R, $U, $XOutport block name 
Function Naming Rule for Value by Reference property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Sendergetref_$X$N$N$G, $M, $R, $U, $XOutport block name 
Data transfer service interface functionReceiver Function Naming Rule property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Transferget_$X$N$N$M, $R, $XData transfer signal name, such as DataTransferAt<Block><Outport><PortNumber> 
Sender Function Naming Rule parameter in service interface Embedded Coder Dictionary, under Service Interfaces > Data Transferset_$X$N$N$M, $R, $XData transfer signal name, such as DataTransferAt<Block><Outport><PortNumber> 
Shared utility functionFunction Naming Rule property in service interface Embedded Coder Dictionary, under Internal > Shared Utility Functions$N$C$C$N, $R, $UName of the function 
Type nameType Name property in Embedded Coder Dictionary, under Memory > Storage Class$R$N$G$MNone$G, $M, $N, $R,$UModel or subsystem with which the data is associatedThis property is visible only if you set the Storage Type property to Structured.
Instance nameInstance Name property in Embedded Coder Dictionary, under Memory > Storage Class$G$N$MNone$G, $M, $N, $R,$UModel or subsystem with which the data is associatedThis property is visible only if you set the Storage Type property to Structured.
Getter functionName of Getter property in Embedded Coder Dictionary, under Memory > Storage Classget_$N$M$N$M, $R, $UAssociated data elementThis property is visible only if you set the Data Access property to Function, the Allowed Access property to Read/Write or Read-only.
GetFunction property in the Code Mappings Editor Property Inspectorget_$NNone$N

This property is visible only for a data element that has the GetSet storage class.

This property does not support regular expression token decorators.

For more information, see Access Data Through Functions with Storage Class GetSet.

Setter functionName of Setter property in Embedded Coder, under Memory > Storage Classset_$N$M$N$M, $R, $UAssociated data elementThis 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 Inspectorset_$NNone$N

This property is visible only for a data element that has the GetSet storage class.

This property does not support regular expression token decorators.

For more information, see Access Data Through Functions with Storage Class GetSet.

Identifier Format Control Limitations

The following 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 models

  • Fixed-point shared utility macros and shared utility functions

  • Simulink rtm macros

  • Header guard macros

  • Generated typedef statements for global data types

  • Generated identifiers for a simulation target such as RSim

Related Examples

More About