Identifier Format Control

You can customize generated identifiers by specifying the Identifier format control parameters on the Code Generation > Identifiers pane in the Configuration Parameters dialog box. For each parameter, you can enter a macro that specifies whether, and in what order, certain text is included within generated identifiers. For example, you can specify that the root model name be inserted into each identifier using the $R token.

The macro can include:

The build process generates each identifier by expanding tokens and inserting the resultant text into the identifier. The tokens are expanded in the order listed in Identifier Format Tokens. Groups of characters are inserted in the positions that you specify around tokens directly into the identifier. Contiguous token expansions are separated by the underscore (_) character.

Identifier Format Tokens

TokenDescription
$C

This token is required for Shared utilities identifier format. If the identifier exceeds the Maximum identifier length, the code generator inserts an 8-character checksum to avoid naming collisions. The position of the $C token in the Identifier format control parameter specification determines the position of the checksum in the generated identifier. For example, if you use the specification $N$C, the checksum is appended to the end of the identifier. This token is available only for shared utilities.

$M

This token is required. If necessary, the code generator inserts name-mangling text to avoid naming collisions. Modify checksum character length by using Shared checksum length parameter. The position of the $M token in the Identifier format control parameter specification determines the position of the name-mangling text in the generated identifier. For example, if you use the specification $R$N$M, the name-mangling text is appended (if required) to the end of the identifier. For more information, see Control Name Mangling in Generated Identifiers.

$U

Insert text that you specify for the $U token. Use the Custom token text parameter to specify this text.

$F

Insert method name (for example, _Update for update method). This token is available only for subsystem methods.

$N

Insert name of object (block, signal or signal object, state, parameter, shared utility function or parameter object) for which identifier is being generated.

$R

Insert root model name into identifier, replacing unsupported characters with the underscore (_) character. When you use referenced models, this token is required in addition to $M (see Avoid Identifier Name Collisions with Referenced Models).

Note: This token replaces the Prefix model name to global identifiers option in previous releases.

$H

Insert tag indicating system hierarchy level. For root-level blocks, the tag is the text root_. For blocks at the subsystem level, the tag is of the form sN_. N is a unique system number assigned by the Simulink® software. This token is available only for subsystem methods and field names of global types.

Note: This token replaces the Include System Hierarchy Number in Identifiers option in previous releases.

$A

Insert data type acronym (for example, i32 for integers) to signal and work vector identifiers. This token is available for local block output variables, local temporary variables, and field names of global types.

Note: This token replaces the Include data type acronym in identifier option in previous releases.

$I
  • 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.

For example, rtu_ for an input argument, rty_ for an output argument, and rtuy_ for an input and output argument. This token is available only for subsystem method arguments.

$G

Insert the name of a storage class that is associated with the data item. This token is also available in the naming rule that you specify for the Header File for a storage class in the Embedded Coder® Dictionary.

$E

Insert the file type. $E represents these instances of file types:

  • capi

  • capi_host

  • dt

  • testinterface

  • private

  • types

This token is required for Header files and Source files.

Identifier Format Control Parameter Values lists the default macro value, the supported tokens, and the applicable restrictions for each Identifier format control parameter.

Identifier Format Control Parameter Values

ParameterDefault ValueSupported TokensRestrictions
Global variables$R$N$M$M, $R, $G,$N,$U$F, $H, $A, $E, and $I are not allowed.
Global types$N$R$M_T$M, $R, $G,$N,$U$F, $H, $A, $E, and $I are not allowed.
Field name of global types$N$M$M, $N, $H, $A, $U$R, $F, $G, $E, and $I are not allowed.
Subsystem methods$R$N$M$F$M, $R, $N, $H, $F, $U$F and $H are empty for Stateflow® functions; $A, $G, $E, and $I are not allowed.
Subsystem method argumentsrt$I$N$M $M, $N, $I, $U$R, $F, $H, $G, $E, and $A are not allowed.
Local temporary variables$N$M$M, $R, $N, $A, $U$F, $H, $G, $E, and $I are not allowed.
Local block output variablesrtb_$N$M$M, $N, $A, $U$R, $F, $H, $G, $E, and $I are not allowed.
Constant macros$R$N$M$M, $R, $N, $U$F, $H, $A, $G, $E, and $I are not allowed.
Shared utilities identifier format$N$C$N, $C, $R, $U$C is required. $M, $F, $H, $A, $G, $E, and $I are not allowed.
EMX array utility functions identifier format
emx$M$N$M, $N,$R$C, $U, $F, $H, $A, $G, $E, and $I are not allowed.
EMX array types identifier format
emxArray_$M$N$M, $N,$R $C, $U, $F, $H, $A, $G, $E, and $I are not allowed.
Header files$R$E$R,$U,$E $C, $M, $N, $F, $H, $A, $G, and $I are not allowed.
Source files$R$E$R,$U,$E $C, $M, $N, $F, $H, $A, $G, and $I are not allowed.
Data files$R_data$R,$U $C, $M, $N, $F, $H, $A, $G, $E, and $I are not allowed.

Non-ERT-based targets (such as the GRT target) implicitly use a default $R$N$M specification. This default specification consists of the root model name, followed by the name of the generating object (signal, parameter, state, and so on), followed by name-mangling text.

For limitations that apply to Identifier format control parameters, see Exceptions to Identifier Formatting Conventions and Identifier Format Control Parameters Limitations.

Control Case with Token Decorators

On the Code Generation > Identifiers pane, you can use token decorators to control the case of generated identifiers. Place a decorator immediately after the target token and enclose the decorator in square brackets [ ]. For example, you can set Global variables to $R[uL]$N$M, which capitalizes the first letter of the model name and forces the remaining characters in the model name to lowercase.

The table shows how to manipulate the expansion of the $R token for a model whose name is modelName.

Desired ExpansionDescriptionToken and Decorator
ModelNameFirst letter of model name is uppercase. Remaining characters are not modified.$R[u]
ModelnameFirst letter of model name is uppercase. Remaining characters are lowercase.$R[uL]
MODELNAMEAll characters are uppercase.$R[U]
modelnameAll characters are lowercase.$R[L]
mODELNAMEFirst letter of model name is lowercase. Remaining characters are uppercase.$R[lU]
modelNameFirst letter of model name is lowercase. Remaining characters are not modified.$R[l]

When you use a decorator, the code generator removes the underscore character (_) that appears between tokens by default. However, you can append each decorator with an underscore: $R[U_]$N. For example, if you set the Global variables parameter to $R[u_]$N[uL]$M for a model named modelName and a DWork structure represented by DW, the result is ModelName_Dw.

Control Formatting of Identifiers

This example shows how you can customize generated identifiers by specifying the Identifier format control parameters on the Code Generation > Identifiers pane in the Configuration Parameters dialog box. To maintain model traceability, it is important that incremental revisions to a model have minimal impact on the identifier names that appear in the generated code. This example shows how you can use name mangling by specifying the Identifier format control parameters to minimally impact the identifier names.

model='rtwdemo_symbols';
open_system(model)

% Cleanup
rtwdemoclean;
close_system(model,0)