Main Content

Control Parentheses in Generated Code

C code contains some syntactically required parentheses, and can contain additional parentheses that change semantics by overriding default operator precedence. C code can also contain optional parentheses that have no functional significance, but only increase the readability of the code. Optional C parentheses vary between two stylistic extremes:

  • Include the minimum parentheses required by C syntax and precedence overrides so that C precedence rules specify all semantics unless overridden by parentheses.

  • Include the maximum parentheses that can exist without duplication so that C precedence rules become irrelevant. Parentheses alone completely specify all semantics.

Understanding code with minimum parentheses can require applying nonobvious precedence rules. Maximum parentheses can hinder code reading by belaboring obvious precedence rules. Various parenthesization standards exist that specify one or the other extreme, or define an intermediate style useful to people who read code.

Control Use of Parentheses

This example shows how you can control parentheses level in the generated code by configuring the Parentheses level parameter.

Open the example model ParenthesizationStyle.

model='ParenthesizationStyle';
open_system(model)

Open the Configuration Parameter dialog box. On the Code Style pane, configure the Parentheses level parameter based on your requirement.

Build the generated code by pressing Ctrl+B.

close_system(model,0)

Related Topics