简体   繁体   English

定义的宏'__CCP_H__'保留给编译器[MISRA 2012规则21.1,必需]

[英]defined macro '__CCP_H__' is reserved to the compiler [MISRA 2012 Rule 21.1, required]

I have two use case for this Misra warning as mentioned below. 我对此Misra警告有两个用例,如下所述。 Does compiler reserve some or specific name for #if defines which can't be used? 编译器是否为#if定义保留了某些名称或特定名称而不能使用?

Currently, I have disabled this warning by //lint !e9071 but do we really need to do anything for such warnings? 目前,我已经通过//lint !e9071禁用了此警告,但是我们真的需要对此类警告采取任何措施吗? Is there any impact or risk if we disabled such warnings? 如果我们禁用此类警告,将会有任何影响或风险吗?

Case 1: 情况1:

#ifndef __CCPPAR_H__
#define __CCPPAR_H__    //lint !e9071


#include "Ccp_Cfg.h"

#endif /* multiple inclusion protection - __CCPPAR_H__ */

Observed warning: 观察到的警告:

 defined macro '__CCPPAR_H__' is reserved to the compiler [MISRA 2012 Rule 21.1, required] 

Case 2: 情况2:

#ifndef __CCP_H__
#define __CCP_H__    //lint !e9071

#include "Ccppar.h"

#define MAJOR   0x02
#define MINOR   0x01

/* other parts of code */ 

#endif

Observed below Misra warnings: 观察到以下Misra警告:

 defined macro '__CCP_H__' is reserved to the compiler [MISRA 2012 Rule 21.1, required] 

The C standard, let alone MISRA, reserves all tokens starting with a double underscore. C标准(更不用说MISRA)保留以双下划线开头的所有令牌。

The practical risk you run is your C standard library implementation using that symbol or even the compiler itself, which clashes with yours. 运行的实际风险是使用该符号甚至编译器本身的C标准库实现,与您的代码冲突。

Part of C11 §7.1.3 Reserved identifiers says: C11§7.1.3的保留标识符的一部分说:

  • All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use. 以下划线,大写字母或另一个下划线开头的所有标识符始终保留供任何使用。
  • All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces. 在普通和标记名称空间中,所有以下划线开头的标识符始终保留为具有文件范围的标识符。

See also What does double underscore ( __const ) mean in C? 另请参见C中的双下划线( __const )是什么意思?

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

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