Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2012-Rule-2.2_b

In this section:
Synopsis

(Required) There shall be no dead code.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A field in a struct is assigned a non-trivial value that is never used.

Coding standards
CERT MSC13-C

Detect and remove unused values

CWE 563

Unused Variable

MISRA C:2012 Rule-2.2

(Required) There shall be no dead code

Code examples

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

typedef struct simpleStruct {
    int a;
} ss_t;

void example(void) {
    ss_t data;
    data.a = 0;
}

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

extern void foo(int num);

typedef struct simpleStruct {
    int a;
} ss_t;

void example(void) {
    ss_t data;
    data.a = 0;
    foo(data.a);
}