A question for Rule8.13

Moderators: misra-c, david ward

Post Reply
Posts: 6
Joined: Thu Feb 20, 2014 6:48 am
Company: HitachiAutomotiveSystems

A question for Rule8.13

Post by KumikoItoh » Tue Feb 25, 2014 5:53 am

I have a question for the Rule8.13.

The rule8.13 is
A pointer should point to a const-qualified type whenever possible

A pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed object

target of the rule16.7 on MISRAC-2004 is "pointer parameter in a fuction".

Why do you delete "pointer parameter in a function"?

Please tell me the reason.

Best Regards,
Kumiko Itoh

Posts: 571
Joined: Thu Jan 05, 2006 1:11 pm

Re: A question for Rule8.13

Post by misra-c » Thu Mar 20, 2014 8:16 am

Rule 8.13 covers all pointers, which includes the "pointer parameter to function" that was covered by rule 16.7 in MISRA-C:2004.

It was felt that programmers should be encouraged to use const where possible and not just on function parameters.

Code: Select all

int32_t fn ( int32_t *ptr )  /* not compliant */
   int32_t *myptr = ptr;     /* not compliant */
   return *myptr;

int32_t fn2 ( const int32_t *ptr2 )  /* compliant */
   const int32_t *myptr2 = ptr2;     /* compliant */
   return *myptr2;
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.8 Declarations and defnitions”