Skip to main content

IAR Embedded Workbench for RX 5.20

CERT-EXP30-C_b

In this section:
Synopsis

Do not depend on the order of evaluation for side effects.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Evaluation of an expression may produce side effects. At specific points during execution, known as sequence points, all side effects of previous evaluations are complete, and no side effects of subsequent evaluations have yet taken place. Do not depend on the order of evaluation for side effects unless there is an intervening sequence point.

Coding standards
CERT EXP30-C

Do not depend on order of evaluation between sequence points

Code examples

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

extern void c(int i, int j);
int glob;

int a(void) {
    return glob + 10;
}

int b(void) {
    glob = 42;
    return glob;
}

void example(void) {
    c(a(), b());
}

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

extern void c(int i, int j);
int glob;

int a(void) {
    return glob + 10;
}
int b(void) {
    glob = 42;
    return glob;
}

void example(void) {
    int a_val, b_val;

    a_val = a();
    b_val = b();

    c(a_val, b_val);
}