Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC++2023-7.11.2 (C++ only)

In this section:
Synopsis

(Required) An array passed as a function argument shall not decay to a pointer

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Found array decaying to pointer in function call This check is identical to MISRAC++2008-5-2-12.

Coding standards
MISRA C++ 2008 5-2-12

(Required) An identifier with array type passed as a function argument shall not decay to a pointer.

Code examples

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

void f(int* p);

void example() {
  int a[4];
  f(a); // Non-compliant
}

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

void f(int (&p)[4]); // Only accepts size 4 arrays

void example() {
  int a[4];
  f(a); // Compliant
}