MISRA Discussion Forums

Full Version: Rule 16.7
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

please look at the following code snippet:

Code:
struct testStruct {
  float32_t varFlt3[3][16];
};

static void f1(struct testStruct * const testStructData);
static void f2(float32_t in_Data[3][16]);

static void f1(struct testStruct * const testStructData)
{
  f2(testStructData->varFlt3);
}

static void f2(float32_t in_Data[3][16])
{
    uint32_t i = 0u;
    for(i = 0u; i < 16u; i++)
    {
      in_Data[0][i] = (float32_t)i;
    }
}

int32_t main(void)
{
  /* This struct should be modified */
  static struct testStruct test;
    f1(&test);
    return 0;
}

My compiler returns a MISRA C rule 16.7 checker error because f1() shall point to a const object. In my opinion, it can't be const, because, the object is modified by f2() inside f1(). The compiler can know this. So who is correct? The compiler vendor or me? If the compiler is correct, how can I overcome this problem? If I modify the parameter of f1() to const I'll get an error because f2() modifies the object, the pointer parameter points to.

Kind regards,

Michael
You are correct and the compiler is wrong.