Just to make sure, does rule 16.3 also apply to declarations of function pointers?
void (*pt2Function)(int);
Sould I give a name to the parameter?
Does that make sense at all?
16.3
Moderators: misra-c, david ward
-
- Posts: 572
- Joined: Thu Jan 05, 2006 1:11 pm
Re: 16.3
Although the rule is worded in terms of declarations, the intention is that it should apply to all prototypes. A declaration of a function pointer should specify the parameter names, for example:
Any type-casts to function pointer types should also specify the parameter names in the prototype.
Code: Select all
void (*pt2Function)(int size);
---
Posted by and on behalf of
the MISRA C Working Group
Posted by and on behalf of
the MISRA C Working Group
-
- Posts: 87
- Joined: Thu Nov 18, 2004 1:39 am
Re: 16.3
So, would the following code, built upon the original example, be in violation of the rule?
Code: Select all
pt2Function a;
void a( int something_other_than_the_word_size ) {
global_int = something_other_than_the_word_size;
}
-
- Posts: 572
- Joined: Thu Jan 05, 2006 1:11 pm
Re: 16.3
The example doesn't violate Rule 16.3 because the prototyped declaration of function a names its parameter.
However, the code doesn't seem to be valid anyway because:
However, the code doesn't seem to be valid anyway because:
- pt2Function is declared as an object, not a type in the original example, so cannot be used to declare the object a
- even if pt2Function were a type, a would be declared as an object and then redeclared as a function
---
Posted by and on behalf of
the MISRA C Working Group
Posted by and on behalf of
the MISRA C Working Group
-
- Posts: 87
- Joined: Thu Nov 18, 2004 1:39 am
Re: 16.3
Good point. Consider, however, the following:
Does this code violate the rule?
Code: Select all
typedef void (*pt2Function)(int stuff);
pt2Function a;
void b(int non_stuff)
{}
void c()
{
a = b;
}