Rule 16.9

6.16 Functions

Moderators: misra-c, david ward

Post Reply
roberto
Posts: 11
Joined: Wed Jun 04, 2008 10:33 pm
Company: University of Parma, Italy

Rule 16.9

Post by roberto » Fri Aug 26, 2011 9:40 pm

Please consider the following snippet:

Code: Select all

static int foo1(void) {
  return 0;
}

static int foo2(void) {
  return 1;
}

int foo() {
  /* Is the following occurrence of `foo1' compliant wrt 16.9? */
  if (&(foo1) == &foo2)
    return 0;
  return 1;
}

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

Re: Rule 16.9

Post by misra-c » Tue Sep 13, 2011 11:02 am

The wording of Rule 16.9 is not precise. The word "preceding" could be interpreted as lexically preceding or semantically preceding. Under the lexical interpretation, the snippet is non-compliant but under the semantic interpretation it is compliant.

The intention of the rule was to prevent a function pointer from being generated when a function call was intended. GIven this, the semantic interpretation is possibly closer to the original intent.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.16 Functions”