避免私有函数的原型声明(在使用前定义)是否违反 MISRA?

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

对C文件中定义的所有函数进行原型声明被认为是一种很好的编程。它还满足 MISRA 准则。 但是我看到开发人员忽略了在使用之前定义的函数的原型声明——在这种情况下似乎不需要原型声明。

有人可以告诉我这是否违反了 MISRA 吗?

它违反了 misra C 的规则 8.1: http://caxapa.ru/thumbs/468328/misra-c-2004.pdf

MISRA 2004 规则 8.1 规定

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

给出的解释如下

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.

所以,是的,你会破坏 MISRA