Model configuration parameters allow you to configure the appearance of the generated code. You can change the style of comments in the code, modify how identifiers are generated, specify code style, and modify code generation template files to specify custom file and function banners.
Add Custom Comments for Variables in the Generated Code
Add selected data object property values as a comment in the general code above that data object identifier.
Add Global Comments in the Generated Code
Add global comments to a Simulink® model so that the comment text appears where you specify in the generated files.
Annotate Code for Justifying Polyspace Checks
This example shows how to turn on comments in the generated code that suppress error detection through Polyspace.
Include MATLAB Code as Comments in Generated Code
Correlate code generated for a MATLAB Function block with MATLAB® source code.
You can customize generated identifiers by specifying the Identifier format control parameters on the Code Generation > Identifiers pane in the Configuration Parameters dialog box.
Specify Identifier Length to Avoid Naming Collisions
Use the Maximum identifier length parameter to limit the number of characters in function, type definition, and variable names.
Specify Reserved Names for Generated Identifiers
Specify a set of names that the code generation process should not use.
Customize Generated Identifier Naming Rules
Customize the naming of identifiers in the generated code.
Avoid Identifier Name Collisions with Referenced Models
Specify parameter values to avoid identifier name collisions with referenced models.
Control Name Mangling in Generated Identifiers
Specify the position and length of name-mangling text in generated identifiers.
Specify Boolean and Data Type Limit Identifiers
Integrate the generated code with your code by specifying
the identifiers that correspond to Boolean false
and true
.
Also, specify the identifiers that correspond to data type limits,
which the generated code uses to determine overflows.
If you use the code generator to produce C or C++ code, your model must not contain keywords that are reserved for internal use.
Maintain Traceability for Generated Identifiers
To verify your model, you can trace back and forth between generated identifiers and corresponding entities within the model.
Exceptions to Identifier Formatting Conventions
There are some exceptions to identifier formatting conventions for type names,
non-Auto
storage classes, and shared utilities.
Identifier Format Control Parameters Limitations
There are some limitations pertaining to how autogenerated identifiers comply with the setting of the Maximum identifier length parameter.
Enhance Readability of Code for Flow Charts
Describes how to convert if-elseif-else code to switch-case statements to enhance readability of generated code.
Enhance Code Readability for MATLAB Function Blocks
Convert if-elseif-else code to switch-case statements.
Improve Data Coherency in Generated Code
Generate a single unique variable for each Data Store read and write operation and thereby enhance Data Coherency.
Control Parentheses in Generated Code
Specify how parentheses are placed in the code.
Optimize Code by Reordering Commutable Operands
Reorder the execution of operands in the generated code to improve efficiency.
Suppress Generation of Default Cases for Unreachable Stateflow Switch Statements
Specify if a default case is generated among switch-case statements.
Replace Multiplication by Powers of Two with Signed Bitwise Shifts
Specify whether to replaces multiplication by powers of two with signed bitwise shifts.
Generate Code Containing Right Shifts on Signed Integers
Specify whether the generated code contains right shifts on signed integers.
Control Cast Expressions in Generated Code
Control the data type casts that the code generator specifies in the generated code.
Customize Code Organization and Format
Custom file processing (CFP) tools allow you to customize the organization and formatting of generated code.
Code Generation Template (CGT) Files
Code Generation Template (CGT) files define the top-level organization and formatting of generated source code and header files.
Custom File Processing (CFP) Templates
A custom file processing (CFP) template imposes a simple structure on the code generation process.
Specify Templates For Code Generation
Create CGT files and CFP templates to use custom file processing features.
Generate Custom File and Function Banners
Using code generation template (CGT) files, you can specify custom file banners and function banners for the generated code files.
Change the Organization of a Generated File
Use data and code templates to change the organization of generated files.
Customize Generated File Names
Customize generated file names by using file naming rules.
Generate Source and Header Files with a Custom File Processing (CFP) Template
This example shows you the process of generating a simple source (.c
or
.cpp
) and header (.h
) file using the example CFP template.
Comparison of a Template and Its Generated File
You can use a template to define what code the code generator adds to the generated file, control the location of code in the file, and optionally insert comments in the generated file.
The code template API includes functions to obtain the names of the standard model files and other model-related information.
This topic describes template symbols and rules for using them.