Rule 18.8 and clarification of "use" of VLA types

Moderators: misra-c, david ward

Post Reply
rgamble
Posts: 14
Joined: Fri Jul 20, 2007 7:54 pm

Rule 18.8 and clarification of "use" of VLA types

Post by rgamble » Fri Oct 27, 2017 5:23 pm

What exactly is meant by the "use" of "variable-length array types"? The examples suggest that the mere declaration of an object of variable length array type violates this rule which makes sense if the declaration is thought of as "using" the VLA type.

The example below declares a pointer to a VLA type and then dereferences the pointer:

Code: Select all

typedef unsigned uint32_t;
typedef int int32_t;

void foo(uint32_t sz, int32_t (*ary)[sz], int32_t val) {
    (*ary)[0] = val;
}
Is the declaration of the pointer parameter ary a violation of this rule? Is the statement that dereferences ary a violation of this rule?

misra-c
Posts: 556
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 18.8 and clarification of "use" of VLA types

Post by misra-c » Fri Dec 08, 2017 9:30 am

Rule 18.8 applies to uses of VLA types. The intention of the MISRA-C working group is that "uses" include the places where the type is "used".
e.g.
  • Declaration of objects;
    typedef int32_t myVLA [x];

Code: Select all

void foo(uint32_t sz, 
         int32_t (*ary)[sz],   /* not compliant */
         int32_t val) 
{
    (*ary)[0] = val;  /* not applicable to this rule */
}
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.18 Pointers and arrays”