Skip to Main Content Skip to Search
Product Documentation

Code Appearance

Configuring Code Comments

Configure how the Simulink Coder code generator inserts comments into generated code, by modifying parameters on the Comments pane.

To...Select...
Include comments in generated codeInclude comments. Selecting this parameter allows you to select one or more comment types to be placed in the code.
Include comments for blocks that were eliminated as the result of optimizations (such as parameter inlining) Show eliminated blocks.
Automatically insert comments that describe a block's code before the code in the generated fileSimulink block / Stateflow object comments.
Include comments for parameter variable names and names of source blocks in the model parameter structure declaration in model_prm.hVerbose comments for SimulinkGlobal storage class. If you do not select this parameter, parameter comments are generated if less than 1000 parameters are declared. This reduces the size of the generated file for models with a large number of parameters. When you select the parameter, parameter comments are generated regardless of the number of parameters.

For descriptions of Comments pane parameters, see Code Generation Pane: Comments in the Simulink Coder reference documentation.

Configuring Generated Identifiers

Configure how the Simulink Coder code generator uses symbols to name identifiers and objects by setting parameters on the Symbols pane.

Two options are available for GRT targets: Maximum identifier length and Reserved names. These are the only symbols options for GRT targets.

The Maximum identifier length field allows you to limit the number of characters in function, type definition, and variable names. The default is 31 characters. This is also the minimum length you can specify; the maximum is 256 characters. Consider increasing identifier length for models having a deep hierarchical structure, and when exercising some of the mnemonic identifier options described below.

Within a model containing Model blocks, no collisions of constituent model names can exist. When generating code from a model that uses model referencing, the Maximum identifier length must be large enough to accommodate the root model name and the name mangling string (if any). A code generation error occurs if Maximum identifier length is too small.

When a name conflict occurs between a symbol within the scope of a higher level model and a symbol within the scope of a referenced model, the symbol from the referenced model is preserved. Name mangling is performed on the symbol from the higher level model.

The Reserved names field allows you to specify the set of keywords that the Simulink Coder code generation process should not use, facilitating code integration where functions and variables from external environments are unknown in the Simulink model. For a list of rules for specifying reserved names, see Reserved names in the Simulink Coder reference documentation.

If your model contains MATLAB Function or Stateflow blocks, the Simulink Coder code generation process can use the reserved names specified for those blocks if you select Use the same reserved names as Simulation Target.

If the Embedded Coder product is installed on your system, the Symbols pane expands to include options for controlling identifier formats, mangle length, scalar inlined parameters, and Simulink data object naming rules. For details, see Customize Generated Identifiers in the Embedded Coder documentation.

For descriptions of Symbols pane parameters, see Code Generation Pane: Symbols in the Simulink Coder reference documentation.

Reserved Keywords

Simulink Coder software reserves certain words for its own use as keywords of the generated code language. Simulink Coder keywords are reserved for use internal to Simulink Coder software and should not be used in Simulink models as identifiers or function names. C reserved keywords should also not be used in Simulink models as identifiers or function names. If your model contains any reserved keywords, the code generation build does not complete and an error message is displayed. To address this error, modify your model to use identifiers or names that are not reserved.

If you are generating C++ code using the Simulink Coder software, your model must not contain both the Reserved Keywords for Code Generation and the C++ Reserved Keywords.

C Reserved Keywords.  

autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
constfloatshortunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile

C++ Reserved Keywords.  

catchfriendprotectedtry
classinlinepublictypeid
const_castmutablereinterpret_casttypename
deletenamespacestatic_castusing
dynamic_castnewtemplatevirtual
explicitoperatorthiswchar_t
exportprivatethrow 

Reserved Keywords for Code Generation.  

absfortranlocalZCErtNaN
asmHAVESTDIOlocalZCSVSeedFileBuffer
boolid_tmatrixSeedFileBufferLen
boolean_Tint_TMODELsingle
byte_Tint8_TMTTID01EQ
char_Tint16_TNCSTATEStime_T
cint8_Tint32_TNULLtrue
cint16_Tint64_TNUMSTTRUE
cint32_TINTEGER_CODEpointer_Tuint_T
creal_TLINK_DATA_BUFFER_SIZEPROFILING_ENABLEDuint8_T
creal32_TLINK_DATA_STREAMPROFILING_NUM_SAMPLESuint16_T
creal64_TlocalBreal_Tuint32_T
cuint8_TlocalCreal32_Tuint64_T
cuint16_TlocalDWorkreal64_TUNUSED_PARAMETER
cuint32_TlocalPRTUSE_RTMODEL
ERTlocalXRT_MALLOCVCAST_FLUSH_DATA
falselocalXdisrtInfvector
FALSElocalXdotrtMinusInf 

Simulink Coder Code Replacement Library Keywords.  The list of code replacement library (CRL) reserved keywords for your development environment varies depending on which CRLs currently are registered. Beyond the default ANSI, ISO, and GNU CRLs provided with Simulink Coder software, additional CRLs might be registered and available for use if you have installed other products that provide CRLs (for example, a target product), or if you have used Embedded Coder APIs to create and register custom CRLs.

To generate a list of reserved keywords for all CRLs currently registered in your environment, use the following MATLAB function:

crl_ids = RTW.TargetRegistry.getInstance.getTflReservedIdentifiers()

This function returns an array of CRL keyword strings. Specifying the return argument is optional.

To generate a list of reserved keywords for the CRL that you are using to generate code, call the function passing the name of the CRL as displayed in the Code replacement library menu on the Code Generation > Interface pane of the Configuration Parameters dialog box. For example,

crl_ids = RTW.TargetRegistry.getInstance.getTflReservedIdentifiers('GNU99 (GNU)')

Here is a partial example of the function output:

>> crl_ids = RTW.TargetRegistry.getInstance.getTflReservedIdentifiers('GNU99 (GNU)')

crl_ids = 

    'exp10'
    'exp10f'
    'acosf'
    'acoshf'
    'asinf'
    'asinhf'
    'atanf'
    'atanhf'
...
    'rt_lu_cplx'
    'rt_lu_cplx_sgl'
    'rt_lu_real'
    'rt_lu_real_sgl'
    'rt_mod_boolean'
    'rt_rem_boolean'
    'strcpy'
    'utAssert'

Construction of Symbols

For GRT, GRT-malloc and RSim targets, the Simulink Coder code generator automatically constructs identifiers for variables and functions in the generated code. These symbols identify

The components of a generated symbol include

The name mangling string is conditionally generated to resolve potential conflicts with other generated symbols.

The length of generated symbols is limited by the Maximum identifier length parameter specified on the Symbols pane of the Configuration Parameters dialog box. When there is a potential name collision between two symbols, a name mangling string is generated. The string has the minimum number of characters required to avoid the collision. The other symbol components are then inserted. If Maximum identifier length is not large enough to accommodate full expansions of the other components, they are truncated. To avoid this outcome, it is good practice to:

Maximum identifier length can be longer for a top model than referenced models. Model referencing can involve additional naming constraints. For information, see Configuring Generated Identifiers and Parameterizing Model References.

The Embedded Coder product provides additional flexibility over how symbols are constructed, by using a Symbol format field that controls the symbol formatting in much greater detail. See Configure Symbols in the Embedded Coder documentation for more information.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS