Rule 16.7

6.16 Functions

Moderators: misra-c, david ward

Post Reply
misterb
Posts: 4
Joined: Fri Sep 09, 2011 4:21 pm
Company: Müller-BBM AST GmbH

Rule 16.7

Post by misterb » Mon Sep 12, 2011 5:54 pm

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

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

Re: Rule 16.7

Post by misra-c » Tue Sep 13, 2011 9:48 am

You are correct and the compiler is wrong.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.16 Functions”