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. 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

TokenDescription
$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, $C expands to a checksum only if the identifier naming rule does not contain $N or if the generated identifier length exceeds the value of the Maximum identifier length model configuration parameter. For shared utilities that you generate from a MATLAB Function block, $C expands to a checksum regardless of the identifier length and whether the identifier naming rule contains $N.

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, $F expands to Update. For Stateflow® functions, $F expands to an empty value.

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 $N token 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

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.

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, $A expands to i32.

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.

  • If the argument is an input, $I expands to u.

  • If the argument is an output, $I expands to y.

  • If the argument is an input and output, $I expands to uy.

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:

  • capi

  • capi_host

  • dt

  • testinterface

  • private

  • types

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 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 that the global variable is associated with, 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 that the field is associated with 
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 that the variable is associated with, 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 that the constant macro is associated with, 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 that the data is associated with

Must end with .h or .hpp.

If Data Scope is set to Exported, must not resolve to the name of a file that is generated for the model, such as model.h or model_types.h.

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 that the data is associated withMust 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 that the data is associated withThis 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 that the data is associated withThis 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, and 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.

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 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