Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 17.4 - can I reference to an array, inside a struct?
#2
For MISRA-C:2004, a strict interpretation of the Rule 17.4 provides you with two options
  • Raise a deviaion
  • Define and use as an array pointer (see below)

Code:
typedef unsigned char uint8_t;
typedef struct s_SomeStruct
{
  uint8_t (*pbuf)[];
  size_t bufsize;
} TSomeStruct;

#define BUFSIZ 10

extern uint8_t buf[ BUFSIZ ];
const TSomeStruct s = { &buf, BUFSIZ }

void main( void )
{
  ...
  (*s.pbuf)[5] = 10u;    /* Example of buffer access */
  ...
}

For MISRA C:2012 this rule has been refined and retargetted as Rule 18.4 to define allowable pointer arithmetic. This would allow what you want to do!
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)