Search code examples
ccoding-stylefunction-prototypesfunction-declarationmisra

Is avoiding prototype declaration for private function (defined before its use) a MISRA violation?


Making prototype declaration for all functions defined in a C file is considered as a good programming. It also satisfies MISRA guideline. But I have seen developers ignoring prototype declarations for functions which are defined before it's used - It seems prototype declaration is unnecessary in such cases.

So can somebody please tell me if it's a MISRA violation ?


Solution

  • Rule 8.1 of MISRA 2004 says that

    Functions shall have prototype declarations and the prototype shall be visible at both the function definition and call.

    The explanation given is as follows

    The use of prototypes enables the compiler to check the integrity of function definitions and calls. Without prototypes the compiler is not obliged to pick up certain errors in function calls. (e.g. different number of arguments from the function body, mismatch in types of arguments between call and definition).

    Function interfaces have been shown to be a cause of considerable problems, and therefore this rule is considered very important.

    So, yes, you would voilate MISRA