Main Content

Arithmetic operations in variant conditions

Diagnostic behavior when variant condition values include arithmetic operations

Model Configuration Pane: Diagnostics

Description

The Arithmetic operations in variant conditions parameter specifies the diagnostic behavior when the variant condition value for a variant block with code compile activation time contains arithmetic operations, such as +, -, and *. Variant blocks have code compile activation time when you set the Variant activation time parameter for the block to code compile.

Variant conditions specified using arithmetic operators can cause differences in behavior between simulation and generated code due to variation in data types used in generated code based on implementation. If your model uses arithmetic operations to specify variant conditions, consider removing the arithmetic operations instead of relaxing the diagnostic behavior.

For example, suppose the variant condition for a Variant Source block is V * W == 10 and you generate code that produces preprocessor conditions for the block. The generated C code contains #if V*W == 10. In simulation, V and W use the int32 data type, but the integer data type used by the compiler for the generated code depends on the implementation. The data type difference can cause a difference in behavior between simulation and generated code for large values of V and D.

Settings

error | warning | none
none

The software does not issue a diagnostic.

warning

The software issues a warning.

This is the default setting for models created using a version prior to R2019a.

error

The software issues an error and terminates the simulation.

This is the default setting for models created using version R2019a and later. If your model uses arithmetic operations to specify variant conditions, consider removing the arithmetic operations instead of relaxing the diagnostic behavior.

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyNo impact
Safety precautionNo impact

Programmatic Use

Parameter: ArithmeticOperatorsInVariantConditions
Type: string | character vector
Values: 'none' | 'warning' | 'error'
Default: 'error'

Version History

Introduced in R2019a

See Also