Main Content

Control Name Mangling in Generated Identifiers

The position of the $M token in the Identifier format control parameter specification determines the position of the name-mangling text in the generated identifiers. 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 Identifier Format Control.

Name-Mangling Text Per Object

Object TypeSource of Mangling Text

Block diagram

Name of block diagram

Simulink® block

Simulink identifier (for details, see Simulink Identifiers)

Simulink parameter

Full name of parameter owner (model or block) and parameter name

Simulink signal

Signal name, full name of source block, and port number

Stateflow® objects

Complete path to Stateflow block and Stateflow computed name (unique within chart)

The length of the name-mangling text is specified by the Minimum mangle length parameter. The default value is 1, but this automatically increases during code generation as a function of the number of collisions. To minimize disturbance to the generated code during development, specify a larger Minimum mangle length. A Minimum mangle length of 4 is a conservative value. A value of 4 allows for over 1.5 million collisions for a particular identifier before the mangle length is increased.

Minimize Name Mangling

The length of generated identifiers is limited by the Maximum identifier length parameter. When a name collision exists, the $M token is expanded to the minimum number of characters required to avoid the collision. Other tokens are expanded in the order listed in Identifier Format Tokens. If the Maximum identifier length is not large enough to accommodate full expansions of the other tokens, partial expansions are used. To avoid partial expansions, it is good practice to:

  • Avoid name collisions. One way to avoid name collisions is to not use default block names (for example, Gain1, Gain2...) when there are many blocks of the same type in the model.

  • Where possible, increase the Maximum identifier length to accommodate the length of the identifiers that you expect to generate.

  • Set the Maximum identifier length parameter to reserve at least three characters for the name-mangling text. The length of the name-mangling text increases as the number of name collisions increases.

    If changes to the model create more or fewer collisions, existing name-mangling text increases or decreases in length. If the length of the name-mangling text increases, additional characters are appended to the existing text. For example, the mangling text 'xyz' can change to 'xyzQ'. For fewer collisions, the name-mangling text 'xyz' changes to 'xy'.