Meaning of rule 8.4 for function prototypes

6.8 Declarations and Definitions

Moderators: misra-c, david ward

Post Reply
Posts: 7
Joined: Fri Oct 07, 2005 7:46 pm
Company: Escher Technologies Ltd.
Location: Ash Vale, Surrey, UK

Meaning of rule 8.4 for function prototypes

Post by dcrocker » Wed Mar 30, 2011 9:02 am

Consider the following:

typedef short int int16_t;

short int foo(short int a);

int16_t foo(int16_t a);

Does this break any MISRA rules? I ask because rule 8.3 states that for a function, the types in the prototype must match the types in the definition *exactly*. However, rule 8.4 states that when an object *or function* is declared more than once, the types in the declarations must be compatible, which is a weaker requirement. Why were the words "or function" included in rule 8.4?

My intepretation is that if my source code includes a definition of function foo, then I must be violating rules 8.3 (because at most one of the prototypes can have types that exactly match the types in the definition); but it my code doesn't include a definition for foo (e.g. because it is in a compiler-supplied library), I am free to provide two or more prototypes for it with non-identical but compatible types.
David Crocker
Escher Technologies Ltd.

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

Re: Meaning of rule 8.4 for function prototypes

Post by misra-c » Wed May 25, 2011 2:45 pm

This was not intentional and it will be corrected in the next version of MISRA C.
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.8 Declarations and Definitions”