Skip to main content

IAR Embedded Workbench for RISC-V 3.40

CERT-EXP40-C_b

In this section:
Synopsis

Do not modify constant objects.

Enabled by default

Yes

Severity/Certainty

Low/Low

lowlow.png
Full description

If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified type, the behavior is undefined.

Coding standards
CERT EXP40-C

Do not modify constant values

Code examples

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

void example(void) {
    char *str  = "const";
    str[0] = 'C';
}

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

void example(void) {
    char str[] = "string";
    str[0] = 'S';
}