Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC2012-Rule-7.4_a

In this section:
Synopsis

(Required) A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char".

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A string literal was found assigned to a variable that is not declared as constant.

Coding standards
MISRA C:2012 Rule-7.4

(Required) A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char"

Code examples

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

void example(void) {
  char *s = "Hello, World!";
}

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

void example(void) {
  const char *s = "Hello, World!";
}