Main Content

Customize Generated Identifiers

If you have Embedded Coder®, you can customize the identifiers in C/C++ code generated from MATLAB® code. For each kind of identifier that you want to customize, set the appropriate identifier format parameter to a macro that specifies the format of the generated identifiers. The macro can include:

  • Valid C or C++ language identifiers (a-z, A-Z, _, 0–9).

  • The tokens listed in the following table. $M is required.

    TokenDescription
    $M

    Code generator inserts name mangling text to avoid naming collisions.

    Required.

    $N

    Code generator inserts the name of the object (global variable, global type, local function, local temporary variable, or constant macro) for which the identifier is generated. Improves readability of generated code.

    Required.

    $R

    Code generator inserts the root project name into identifier, replacing unsupported characters with the underscore (_) character.

Customize Identifiers by Using the MATLAB Coder App

  1. On the Generate Code page, to open the Generate dialog box, click the Generate arrow .

  2. Set Build type to one of the following:

    • Source Code

    • Static Library

    • Dynamic Library

    • Executable

  3. Click More Settings.

  4. On the Code Appearance tab, under Identifier Format, for each kind of identifier that you want to customize, enter the macro.

    ParameterDefault Macro
    Global variables$M$N
    Global types$M$N
    Field name of global types$M$N
    Local functions$M$N
    Local temporary variables$M$N
    Constant macros$M$N
    EMX Array TypesemxArray_$M$N
    EMX Array Utility Functionsemx$M$N

For example, suppose that Global variables has the value glob_$M$N. For a global variable named g, when name mangling is not required, the generated identifier is glob_g. If name mangling is required, the generated identifier includes the name mangling text.

Customize Generated Identifiers by Using the Command-Line Interface

  1. Create a code configuration object for a library or executable program. For example:

    cfg = coder.config('lib','ecoder',true);
    

  2. For each kind of identifier that you want to customize, specify the macro as a character vector.

    ParameterDescription Default Macro
    CustomSymbolStrGlobalVarGlobal variables'$M$N'
    CustomSymbolStrTypeGlobal types'$M$N'
    CustomSymbolStrFieldField name of global types'$M$N'
    CustomSymbolStrFcnLocal functions'$M$N'
    CustomSymbolStrTmpVarLocal temporary variables'$M$N'
    CustomSymbolStrMacroConstant macros'$M$N'
    CustomSymbolStrEMXArrayEMX Array Types'emxArray_$M$N'
    CustomSymbolStrEMXArrayFcnEMX Array Utility Functions'emx$M$N'

    For example:

    cfg.CustomSymbolStrGlobalVar = 'glob_$M$N';

For a global variable named g, when name mangling is not required, the generated identifier is glob_g. If name mangling is required, the generated identifier includes the name mangling text.

See Also

Related Topics