宏定义的数量超过4095-程序并不严格符合ISO:C99

发布于 2025-02-13 12:14:17 字数 223 浏览 0 评论 0原文

我在Misra警告下观察到。

[l]宏定义的数量超过4095-程序并不严格符合ISO:C99。 MISRA- 2012年,消息标识符:0380

代码行:

#include "COMH_ExteriorLightUI.h"

根据Misra规则,我们对代码中要使用的宏观定义数量有任何限制?

我在尝试包含标头文件时会遇到此错误。

I am observing below MISRA Warnings.

[L] Number of macro definitions exceeds 4095 - program does not conform strictly to ISO:C99.
MISRA - 2012, Message Identifier : 0380

Code line:

#include "COMH_ExteriorLightUI.h"

Do we have any limit on number of MACRO defination to be used in code according to MISRA rules ?

I am getting this error while trying to include header file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝颜夕 2025-02-20 12:14:17

C语言(C17 5.2.4.1)仅保证支持单个翻译单元中的4095个不同的宏标识符。如果您的宏比这更多,则您的代码是不可存储的,并且可能不会编译。

您只能通过更好的程序设计来解决此问题,通过将巨大的.c文件分成几个,并本地化宏,这些宏不需要在该.h/.c文件对之外暴露出来。

例如,您可以拥有一个公共标头,该标头在两个.c文件中实现,其中一个.c文件包含公共API的函数定义,而另一个.c文件包含内部函数。将第二个私有.c文件包含在拨打者不需要的宏中,或者将宏内的宏包含在该私有.c文件中。

另外,避免了创建“超级标头”的某种常见但非常糟糕的练习,进而包括项目中的所有其他标题文件。这种风险不仅会炸毁预处理器,而且还会在项目中每个无关的文件之间产生紧密的耦合。对于关键系统,这种设计是完全无法接受的。

The C language (C17 5.2.4.1) only guarantees that 4095 different macro identifiers in a single translation unit are supported. If you have more macros than that, your code is non-portable and may not compile.

You can only solve this by better program design, by splitting huge .c files into several and localize macros that don't need to be exposed outside that .h/.c file pair.

For example, you could have a public header, which is implemented in two .c files where one .c file contains the function definitions for the public API and the other .c file contains internal functions. Have this second, private .c file include it's own .h file with macros that the caller need not know about, or alternatively place the macros inside that private .c file.

Also, avoid a somewhat common but very bad practice of creating a "super header" which in turn includes every other header file in the project. Not only does that risk blow the preprocessor, it also creates a tight coupling between every single, unrelated file in the project. Such a design is completely unacceptable for critical systems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文