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

标签 c coding-style function-prototypes function-declaration misra

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

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

最佳答案

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

关于c - 避免私有(private)函数的原型(prototype)声明(在使用前定义)是否违反 MISRA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34872978/

相关文章:

c - 调试时从寄存器中提取单个位

javascript - 正确的 JavaScript 对象

c++ - 即使使用#include <Shlobj.h> 和#pragma 注释(lib, "Shell32.lib")也无法调用 SHGetKnownFolderPath()

c - 在源代码级别使用 GCC __builtin_object_size 是否有任何动机?

c# - 检查所有鼠标按钮的按钮状态

c - 在 emacs 中将预处理器指令缩进为 C 代码

python - urls.py redirect with URL reversal and parameters——有没有更简单的方法?

c++ - 函数原型(prototype)混淆

c++ - 将定义的函数的函数原型(prototype)放在不同的源文件(不是头文件)中是否合法/好?

c - 如何使线程操作的结果对进程中的所有其他线程可见?