Skip to main content

IAR Embedded Workbench for RISC-V 3.40

CERT-PRE31-C

In this section:
Synopsis

Avoid side effects in arguments to unsafe macros.

Enabled by default

Yes

Severity/Certainty

Low/Low

lowlow.png
Full description

An unsafe function-like macro is one whose expansion results in evaluating one of its parameters more than once or not at all. Never invoke an unsafe macro with arguments containing side effects.

Coding standards
CERT PRE31-C

Avoid side effects in arguments to unsafe macros

Code examples

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

#define ABS(x) (((x) < 0) ? -(x) : (x))

void example(void) {
    int n = 0;
    int m = ABS(++n);
}

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

#define ABS(x) (((x) < 0) ? -(x) : (x))

void example(void) {
    int n = 0;
    ++n;
    int m = ABS(n);
}