Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC2012-Rule-18.9

In this section:
Synopsis

(Required) An object with temporary lifetime shall not undergo array-to-pointer conversion

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Array-to-pointer conversion of an object with temporary lifetime.

Coding standards
MISRA C:2012 Rule-18.9

(Required) An object with temporary lifetime shall not undergo array-to-pointer conversion

Code examples

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

#include <stdint.h>

struct S1 { int32_t array[10];};
struct S1 getS1 (void);

void example()
{
  int32_t * p = 0;
  p = getS1().array; /* Non-compliant - temporary storage duration */
}

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

#include <stdint.h>

struct S1 { int32_t array[10];};
struct S1 s1;

void example()
{
  int32_t * p = 0;
  p = s1.array; /* Compliant - not temporary storage duration */
}