| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Real-Time Workshop Embedded Coder |
| Contents | Index |
| Learn more about Real-Time Workshop Embedded Coder |

| On this page… |
|---|
Real-Time Workshop: Code Style Tab Overview Preserve operand order in expression Preserve condition expression in if statement |
Control optimizations for readability in generated code.
This tab appears only if you specify an ERT based system target file.
Specify parenthesization style for generated code.
Default: Nominal (Optimize for readability)
Inserts parentheses only where required by ANSI[1] C or C++, or needed to override default precedence. For example:
isZero = var == 0;
if (isZero == 1 && (value < 3.7 ||value > 9.27)) {
/* code */
}Inserts parentheses in a way that compromises between readability and visual complexity. The exact definition can change between releases.
Includes parentheses everywhere needed to specify meaning without relying on operator precedence. Code generated with this setting conforms to MISRA®[2] requirements. For example:
isZero = (var == 0);
if ((isZero == 1) && ((value < 3.7) || (value > 9.27))) {
/* code */
}
| Parameter: ParenthesesLevel |
| Type: string |
| Value: 'Minimum' | 'Nominal' | 'Maximum' |
| Default: 'Nominal' |
| Application | Setting |
|---|---|
| Debugging | Nominal (Optimized for readability) |
| Traceability | Nominal (Optimized for readability) |
| Efficiency | Minimum (Rely on C/C++ operators for precedence) |
| Safety precaution | Maximum (Specify precedence with parentheses) |
Specify whether to preserve order of operands in expressions.
Default: off
Preserves the expression order specified in the model. Select this option to increase readability of the code or for code traceability purposes.
A*(B+C)
Optimizes efficiency of code for nonoptimized compilers by reordering commutable operands to make expressions left-recursive. For example:
(B+C)*A
| Parameter: PreserveExpressionOrder |
| Type: string |
| Value: 'on' | 'off' |
| Default: 'off' |
| Application | Setting |
|---|---|
| Debugging | On |
| Traceability | On |
| Efficiency | Off |
| Safety precaution | On |
Specify whether to preserve empty primary condition expressions in if statements.
Default: off
Preserves empty primary condition expressions in if statements, such as the following, to increase the readability of the code or for code traceability purposes.
if expression1
else
statements2;
endOptimizes empty primary condition expressions in if statements by negating them. For example, consider the following if statement:
if expression1
else
statements2;
endBy default, the code generator negates this statement as follows:
if ~expression1
statements2;
end| Parameter: PreserveIfCondition |
| Type: string |
| Value: 'on' | 'off' |
| Default: 'off' |
| Application | Setting |
|---|---|
| Debugging | On |
| Traceability | On |
| Efficiency | Off |
| Safety precaution | On |
Specify whether to generate code for if-elseif-else decision logic as switch-case statements.
This readability optimization works on a per-model basis and applies only to:
Flow graphs in Stateflow® charts
Embedded MATLAB® functions in Stateflow charts
Embedded MATLAB Function blocks in that model
Default: off
Generate code for if-elseif-else decision logic as switch-case statements.
For example, assume that you have the following logic pattern:
if (x == 1) {
y = 1;
} else if (x == 2) {
y = 2;
} else if (x == 3) {
y = 3;
} else {
y = 4;
}Selecting this check box converts the if-elseif-else pattern to the following switch-case statements:
switch (x) {
case 1:
y = 1; break;
case 2:
y = 2; break;
case 3:
y = 3; break;
default:
y = 4; break;
}Preserve if-elseif-else decision logic in generated code.
| Parameter: ConvertIfToSwitch |
| Type: string |
| Value: 'on' | 'off' |
| Default: 'off' |
| Application | Setting |
|---|---|
| Debugging | No impact |
| Traceability | Off |
| Efficiency | On (execution, ROM), No impact (RAM) |
| Safety precaution | No impact |
Specify whether to include the extern keyword in function declarations in the generated code.
Note The extern keyword is optional for functions with external linkage. It is considered good programming practice to include the extern keyword in function declarations for code readability. |
Default: on
Include the extern keyword in function declarations in the generated code. For example, the generated code for the demo model rtwdemo_hyperlinks contains the following function declarations in rtwdemo_hyperlinks.h:
/* Model entry point functions */ extern void rtwdemo_hyperlinks_initialize(void); extern void rtwdemo_hyperlinks_step(void);
The extern keyword explicitly indicates that the function has external linkage. The function definitions in this example are in the generated file rtwdemo_hyperlinks.c.
Remove the extern keyword from function declarations in the generated code.
| Parameter: PreserveExternInFcnDecls |
| Type: string |
| Value: 'on' | 'off' |
| Default: 'on' |
| Application | Setting |
|---|---|
| Debugging | No impact |
| Traceability | No impact |
| Efficiency | No impact |
| Safety precaution | No impact |
For more information on code style options, see Real-Time Workshop Pane: Code Style
[1] ANSI is a registered trademark of the American National Standards Institute, Inc.
[2] MISRA is a registered trademarks of MIRA Ltd, held on behalf of the MISRA Consortium.
![]() | Real-Time Workshop Pane: SIL and PIL Verification | Real-Time Workshop Pane: Templates | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |