简体   繁体   English

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

[英]Number of macro definitions exceeds 4095 - program does not conform strictly to ISO:C99

I am observing below MISRA Warnings.我在 MISRA 警告下方观察。

[L] Number of macro definitions exceeds 4095 - program does not conform strictly to ISO:C99. [L] 宏定义数量超过 4095 - 程序不严格符合 ISO:C99。 MISRA - 2012, Message Identifier : 0380 MISRA - 2012,消息标识符: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 ?根据 MISRA 规则,我们对代码中使用的宏定义的数量有任何限制吗?

I am getting this error while trying to include header file.尝试包含头文件时出现此错误。

The C language (C17 5.2.4.1) only guarantees that 4095 different macro identifiers in a single translation unit are supported. C 语言 (C17 5.2.4.1) 仅保证在单个翻译单元中支持 4095 个不同的宏标识符。 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.您只能通过更好的程序设计来解决这个问题,将巨大的 .c 文件拆分为多个并本地化不需要在该 .h/.c 文件对之外公开的宏。

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.例如,您可以有一个公共标头,它在两个 .c 文件中实现,其中一个 .c 文件包含公共 API 的函数定义,另一个 .c 文件包含内部函数。 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.让第二个私有 .c 文件包含它自己的 .h 文件,其中包含调用者不需要知道的宏,或者将宏放在该私有 .c 文件中。

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.这样的设计对于关键系统来说是完全不能接受的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM