29-09-2004, 12:20 PM
> What is the intended interpretation of Misra C:1998 rules 104 and 105?
Although the wording does not say so, I think the intent of these rules
is to apply to objects declared to have a pointer to function type.
> Misra C:1998 rule 104 reads \"Non-constant pointers to functions shall
> not be used\"
As written this rule prohibits the use of identifiers declared as functions.
For instance, in:
> 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\".
I think the intent was to say:
\"All functions pointed to by an object having a pointer to function
type shall ...\"
> 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.
Rule 105 is needed to stop me writing:
Rule 104 only requeries the use of const, it does not
say anything about or parameter types.
Although the wording does not say so, I think the intent of these rules
is to apply to objects declared to have a pointer to function type.
> Misra C:1998 rule 104 reads \"Non-constant pointers to functions shall
> not be used\"
As written this rule prohibits the use of identifiers declared as functions.
For instance, in:
Code:
void f(void)
{ /* ... */ }
void g(void)
{
f(); /* this violates rule 104 since f has a non-constant pointer to function
* type
*/
}
> 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\".
I think the intent was to say:
\"All functions pointed to by an object having a pointer to function
type shall ...\"
> 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.
Rule 105 is needed to stop me writing:
Code:
extern int f(int, long);
extern char g(float);
/* ... */
some_call((int (* const)(int))f);
some_call((int (* const)(int))g);
Rule 104 only requeries the use of const, it does not
say anything about or parameter types.
<r>Applications conformance testing: <URL url="http://www.knosof.co.uk/cbook">http://www.knosof.co.uk/cbook</URL></r>