Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2012-Rule-12.1

In this section:
Synopsis

(Advisory) The precedence of operators within expressions should be made explicit

Enabled by default

No

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Implicit operator precedence was detected, without parenthesis to make it explicit. This check is identical to MISRAC++2008-5-0-2, MISRAC++2023-8.0.1, MISRAC2012-Rule-12.1, MISRAC2004-12.1.

Coding standards
MISRA C:2004 12.1

(Advisory) Limited dependence should be placed on the C operator precedence rules in expressions.

MISRA C:2012 Rule-12.1

(Advisory) The precedence of operators within expressions should be made explicit

MISRA C++ 2008 5-0-2

(Advisory) Limited dependence should be placed on C++ operator precedence rules in expressions.

MISRA C++ 2023 8.0.1

(Advisory) Parentheses should be used to make the meaning of an expression appropriately explicit

Code examples

The following code example fails the check and will give a warning:

void example(void) {
    int i;
    int j;
    int k;
    int result;

    result = i + j * k;
}

The following code example passes the check and will not give a warning about this issue:

void example(void) {
    int i;
    int j;
    int k;
    int result;

    result = i + (j - k);
}