Rule 16.5

6.16 Functions

Moderators: misra-c, david ward

Post Reply
Posts: 3
Joined: Mon Aug 03, 2009 12:59 pm
Company: Baker Hughes INTEQ

Rule 16.5

Post by hanthen » Tue Aug 02, 2011 1:11 pm

Does this rule apply also to function pointers?
If I want to declare a function pointer which can be used for pointers to functions with different arguments, something like the following is useful:

uint8_t (* gen_u8p)();

Is this intended to be prohibited by the rule?

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

Re: Rule 16.5

Post by misra-c » Tue Aug 09, 2011 9:47 am

No, rule 16.5 does not apply to function pointers. However, note that:
  • Rule 8.1 requires a function prototype to be visible at call
  • Rule 11.1 does not permit a non-prototyped function pointer to be converted to a prototyped one
Therefore, a pointer to a non-prototyped function cannot be used to call a function and cannot be converted to a pointer that could be used to call a function.

The rationale is to avoid the undefined behaviour that occurs when a function is called by means of a pointer whose type is not compatible with the called function.
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.16 Functions”