Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA C:1998 Rule 104 and rule 105
#1
First, good idea to set up the forum, hope it will be frequently visited by engineers working with Misra C. Nice to be one of the first users of the forum :-)

As there is no section specifically dedicated to Misra C:1998 I place my question in the general question section.

What is the intended interpretation of Misra C:1998 rules 104 and 105?

Misra C:1998 rule 104 reads \"Non-constant pointers to functions shall not be used\"
One may interpret this rule as that the only allowed use and declaration of a function pointer is as in the example below

Example:
Code:
typedef U16_t( *const MyFuncPointer_t) (U16_t);

U16_t MyFunc(U16_t MyInput)
{
  return (MyInput + 2u);
}

MyFuncPointer_t MyFuncPointer = MyFunc;

void main(void)
{
     printf(\"\\nReturn: %i\\n\\n\",MyFuncPointer(4u));
}

If the above interpretation is correct, then the function pointer should always be declared as a constant and can never point at another function during runtime.

Rule 105 reads: \"All the functions pointed to by a single pointer to function shall be identical in the number and type of parameters and the return type\".

We interpret rule 105 as it is allowed for one single function pointer to point at diffferent functions during runtime. But with the conservative interpretation of rule 104, a function pointer may never change the function it points at during runtime and thus conflicts with rule 105, i.e. rule 105 would be superfluous.

What would be the correct way to interpret rule 104 and rule 105?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)