Main Content

Model Configuration Parameters: Comments

The Code Generation > Comments category includes parameters for configuring the comments in the generated code. These parameters require a Simulink® Coder™ license. Additional parameters available with an ERT-based target require an Embedded Coder® license.

Code Comments are generated automatically or you can add them to the code.

Code comments have the following uses:

  • Enhance the readability and traceability of code

  • Convey information among users

  • Enhance code search in code base

Code Comments can be classified into Auto generated and Custom comments. Auto generated comments are automatically generated by the software during code generation and the user adds Custom comments.

On the Configuration Parameters dialog box, the following configuration parameters are on the Code Generation > Comments pane.

Auto generated comments

ParameterDescription

Include comments

Specify which comments are in generated files.

Simulink block comments

Specify whether to insert Simulink block comments.

Trace to model using (Embedded Coder)

Specify format of comments for Simulink blocks, Stateflow® elements and MATLAB® function blocks.

Stateflow object comments

Specify whether to insert Stateflow object comments.

MATLAB source code as comments

Specify whether to insert MATLAB source code as comments.

Show eliminated blocks

Specify whether to insert eliminated block's comments.

Verbose comments for 'Model default' storage class

Reduce code size or improve code traceability by controlling the generation of comments.

Operator annotations (Embedded Coder)

Specify whether to include operator annotations for Polyspace® in the generated code as comments.

Custom comments

ParameterDescription

Simulink block descriptions (Embedded Coder)

Specify whether to insert descriptions of blocks into generated code as comments.

Stateflow object descriptions (Embedded Coder)

Specify whether to insert descriptions of Stateflow objects into generated code as comments.

Simulink data object descriptions (Embedded Coder)

Specify whether to insert descriptions of Simulink data objects into generated code as comments.

Requirements in block comments (Embedded Coder)

Specify whether to include requirement descriptions assigned to Simulink blocks in generated code as comments.

Custom comments (MPT objects only) (Embedded Coder)

Specify whether to include custom comments for module packaging tool (MPT) signal and parameter data objects in generated code.

MATLAB user comments (Embedded Coder)

Specify whether to include MATLAB user comments as comments.

Custom comments function (Embedded Coder)

Specify a file that contains comments to be included in generated code for module packing tool (MPT) signal and parameter data objects.

The following configuration parameters are under the Advanced parameters.

ParameterDescription

Comment style (Embedded Coder)

Specify a multi-line or single-line comment style for generated C or C++ code.

Insert Polyspace comments (Embedded Coder)

Specify whether to insert code comments for Polyspace block annotations.

  • The code generation software automatically inserts comments into the generated code for custom blocks. Therefore, you do not need to include block comments in the associated TLC file for a custom block.

    Note

    If you have existing TLC files with manually inserted comments for block descriptions, the code generation process emits these comments instead of the automatically generated comments. Consider removing existing block comments from your TLC files. Manually inserted comments might be poorly formatted in the generated code and code-to-model traceability might not work.

  • For virtual blocks or blocks that have been removed due to block reduction, comments are not generated.

  • When you configure the code generator to produce code that includes comments, the code generator includes text for model parameters, block names, signal names, and Stateflow object names in the generated code comments. If the text includes characters that are unrepresented in the character set encoding for the model, the code generator replaces the characters with XML escape sequences. For example, the code generator replaces the Japanese full-width Katakana letter ア with the escape sequence ア. For more information, see Internationalization and Code Generation.

  • When you set the model configuration parameter Default parameter behavior to Tunable, the code generator adds different comments about numeric block parameters in the generated code depending on the numeric value of the block parameter and the output data type. For instance, code generator adds:

    • Computed Parameter as a comment when the numeric value of the block parameter needs type conversion to match the output data type.

    • Expression as a comment when the numeric value of the block parameter matches the output data type without type conversion.

    Simulink interprets the data type of a numeric parameter as double unless you explicitly specify otherwise. Generate code for the following model:

    Image of output data type interpretation

    // Parameters (auto storage)
    struct P_test_parameter_T_ {
      real_T Constant1_Value;              // Expression: 200
                                              //  Referenced by: '<Root>/Constant1'
    
      real_T Constant2_Value;              // Computed Parameter: Constant2_Value
                                              //  Referenced by: '<Root>/Constant2'
    
      int32_T Constant3_Value;             // Computed Parameter: Constant3_Value
                                              //  Referenced by: '<Root>/Constant3'
    };

    When the constant value is 200 and the output data type is double, the code generator adds Expression as a comment. Simulink interprets the data type of the constant value as double and without type conversion it matches the output data type.

    When the constant value is uint8(200) and the output data type is double, the code generator adds Computed Parameter as a comment. The constant value requires type conversion to match the output data type.

    When the constant value is 500 and the output data type is int32, the code generator adds Computed Parameter as a comment. The constant value requires type conversion to match the output data type.

Related Topics