Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 16.7
#1
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
<t></t>
Reply
#2
You are correct and the compiler is wrong.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)