Main Content

Parentheses level

Parenthesization style for generated code

Model Configuration Pane: Code Generation / Code Style

Description

Specify parenthesization style for generated code.

Settings

Nominal (Optimize for readability) (default) | Minimum (Rely on C/C++ operators for precedence) | Standards (Parentheses for Standards Compliance) | Maximum (Specify precedence with parentheses)

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 to override default precedence.

If you generate C/C++ code using the minimum level, for certain settings in some compilers, you can receive compiler warnings. To eliminate these warnings, try the nominal level.

Nominal (Optimize for readability)

Inserts parentheses in a way that compromises between readability and visual complexity.

Standards (Parentheses for Standards Compliance)

Inserts parentheses in a way that requires both MISRA®2 compliance and better code readability. Code generated with this setting conforms to MISRA requirements.

Maximum (Specify precedence with parentheses)

Includes parentheses to specify meaning without relying on operator precedence. Code generated with this setting conforms to MISRA requirements.

Examples

expand all

Compare the parentheses in the generated code when you set Parentheses level to different values.

Here is generated code that generated using the default Parentheses level value Nominal (Optimize for readability):

Out = ((In2 - In1 > 1.0) && (In2 > 2.0));

Here is the same code generated with Parentheses level set to Minimum (Rely on C/C++ operators for precedence):

Out = In2 - In1 > 1.0 && In2 > 2.0;

Here is the same code generated with Parentheses level set to Standards (Parentheses for Standards Compliance):

Out = ((In2 - In1 > 1.0) && (In2 > 2.0));

Here is the same code generated with Parentheses level set to Maximum (Specify precedence with parentheses):

 Out = (((In2 - In1) > 1.0) && (In2 > 2.0));

Recommended Settings

ApplicationSetting
DebuggingNominal (Optimized for readability)
TraceabilityNominal (Optimized for readability)
EfficiencyMinimum (Rely on C/C++ operators for precedence)
Safety precaution

No recommendation

Programmatic Use

Parameter: ParenthesesLevel
Type: character vector
Value: 'Minimum' | 'Nominal' | 'Standards' | 'Maximum'
Default: 'Nominal'

Version History

Introduced in R2006b


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.