Main Content

Model Configuration Parameters: Code Style

The Code Generation > Code Style category includes parameters for configuring the appearance of the generated code. These parameters require a Simulink® Coder™ license. Additional parameters for an ERT-based target require an Embedded Coder® license.

You can change the code style, cast expressions, and indentation of your generated code to conform to certain coding standards.

Code style modifications have the following uses:

  • Enhance the readability and traceability of code

  • Convey information across files

  • Enhance the efficiency of the generated code

  • Allow memory manipulation through type casting

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

ParameterDescription

Parentheses level

Specify parenthesization style for generated code.

Preserve operand order in expression

Specify whether to preserve order of operands in expressions.

Preserve condition expression in if statement

Specify whether to preserve empty primary condition expressions in if statements.

Convert if-elseif-else patterns to switch-case statements

Specify whether to generate code for if-elseif-else decision logic as switch-case statements.

Preserve extern keyword in function declarations

Specify whether to include the extern keyword in function declarations in the generated code.

Preserve static keyword in function declarations

Specify whether to include the static keyword in function declarations in the generated code.

Suppress generation of default cases for Stateflow switch statements if unreachable

Specify whether to generate default cases for switch-case statements in the code for Stateflow® charts.

Replace multiplications by powers of two with signed bitwise shifts

Specify whether to replace multiplications by powers of two with signed bitwise shifts.

Allow right shifts on signed integers

Specify whether to allow signed right bitwise shifts in the generated C/C++ code. 

Casting modes

Specify how the code generator casts data types for variables.

Static array container type

Specify the container type for arrays in the generated code. Choose either C-style array or std::array.

Indent style

Specify style for the placement of braces in generated code.

Indent size

Specify indent size for generated code.

Newline style

Specify the newline style for generated code.

Maximum line width

Specify the maximum line width for wrapping the generated code.

Related Topics