Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2012-Rule-18.10

In this section:
Synopsis

(Mandatory) Pointers to variably-modified array types shall not be used

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Pointer to variably-modified array type used.

Coding standards
MISRA C:2012 Rule-18.10

(Mandatory) Pointer to variably-modified array types shall not be used

Code examples

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

/* Non-compliant */
void f1 (unsigned int n, unsigned int (* a) [n]) {
  unsigned int ( *p )[ 20 ]; 
  p = a; /* undefined unless n == 20, but types always assumed compatible */
}

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

/* Compliant */
void f2 (unsigned int n, unsigned int a[n]) { 
  unsigned int * p;
  p = a; /* pointed-to type is not variably-modified, always well-defined */
}