gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 01:24:04 26 4
gpt4 key购买 nike

为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 considerableproblems, and therefore this rule is considered very important.

所以,是的,你会破坏 MISRA

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com