Real-Time Workshop Pane: Code Style

Code Style Tab Overview

Control optimizations for readability in generated code.

Configuration

This tab appears only if you specify an ERT based system target file.

See Also

Code Style Pane

Parentheses level

Specify parenthesization style for generated code.

Settings

Default: Nominal (Optimize for readability)

Minimum (Rely on C/C++ operators for precedence)

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 */
   }
Nominal (Optimize for readability)

Inserts parentheses in a way that compromises between readability and visual complexity. The exact definition can change between releases.

Maximum (Specify precedence with parentheses)

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 */
   }

Command-Line Information

Parameter: ParenthesesLevel
Type: string
Value: 'Minimum' | 'Nominal' | 'Maximum'
Default: 'Nominal'

Recommended Settings

ApplicationSetting
DebuggingNominal (Optimized for readability)
TraceabilityNominal (Optimized for readability)
EfficiencyMinimum (Rely on C/C++ operators for precedence)
Safety precautionMaximum (Specify precedence with parentheses)

See Also

Controlling Parenthesization

Preserve operand order in expression

Specify whether to preserve order of operands in expressions.

Settings

Default: off

On

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)
Off

Optimizes efficiency of code for nonoptimized compilers by reordering commutable operands to make expressions left-recursive. For example:

(B+C)*A

Command-Line Information

Parameter: PreserveExpressionOrder
Type: string
Value: 'on' | 'off'
Default: 'off'

Recommended Settings

ApplicationSetting
DebuggingOn
TraceabilityOn
EfficiencyOff
Safety precautionOn

Preserve condition expression in if statement

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

Settings

Default: off

On

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;
end
Off

Optimizes empty primary condition expressions in if statements by negating them. For example, consider the following if statement:

if expression1
else
       statements2;
end

By default, the code generator negates this statement as follows:

if ~expression1
        statements2;
end

Command-Line Information

Parameter: PreserveIfCondition
Type: string
Value: 'on' | 'off'
Default: 'off'

Recommended Settings

ApplicationSetting
DebuggingOn
TraceabilityOn
EfficiencyOff
Safety precautionOff


[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.

  


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