Page 1 of 1

Rule 16.7

Posted: Mon Sep 12, 2011 5:54 pm
by misterb
Hello,

please look at the following code snippet:

Code: Select all

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

Re: Rule 16.7

Posted: Tue Sep 13, 2011 9:48 am
by misra-c
You are correct and the compiler is wrong.