定义的宏“__CCP_H__”保留给编译器[MISRA 2012 Rule 21.1, required]
defined macro '__CCP_H__' is reserved to the compiler [MISRA 2012 Rule 21.1, required]
我有两个关于此 Misra 警告的用例,如下所述。编译器是否为 #if 定义不能使用的某些或特定名称?
目前,我已通过 //lint !e9071
禁用此警告,但我们真的需要为此类警告做任何事情吗?如果我们禁用此类警告,是否有任何影响或风险?
案例一:
#ifndef __CCPPAR_H__
#define __CCPPAR_H__ //lint !e9071
#include "Ccp_Cfg.h"
#endif /* multiple inclusion protection - __CCPPAR_H__ */
观察到的警告:
defined macro '__CCPPAR_H__' is reserved to the compiler [MISRA 2012
Rule 21.1, required]
案例 2:
#ifndef __CCP_H__
#define __CCP_H__ //lint !e9071
#include "Ccppar.h"
#define MAJOR 0x02
#define MINOR 0x01
/* other parts of code */
#endif
观察到以下 Misra 警告:
defined macro '__CCP_H__' is reserved to the compiler [MISRA 2012
Rule 21.1, required]
C 标准,更不用说 MISRA,保留所有以双下划线开头的标记。
您 运行 的实际风险是您的 C 标准库实现使用该符号甚至编译器本身,这与您的冲突。
C11 §7.1.3 Reserved identifiers 的一部分说:
- 所有以下划线和大写字母或其他下划线开头的标识符始终保留供任何使用。
- 所有以下划线开头的标识符始终保留用作普通和标记名称空间中具有文件范围的标识符。
另见 What does double underscore (__const
) mean in C?
我有两个关于此 Misra 警告的用例,如下所述。编译器是否为 #if 定义不能使用的某些或特定名称?
目前,我已通过 //lint !e9071
禁用此警告,但我们真的需要为此类警告做任何事情吗?如果我们禁用此类警告,是否有任何影响或风险?
案例一:
#ifndef __CCPPAR_H__
#define __CCPPAR_H__ //lint !e9071
#include "Ccp_Cfg.h"
#endif /* multiple inclusion protection - __CCPPAR_H__ */
观察到的警告:
defined macro '__CCPPAR_H__' is reserved to the compiler [MISRA 2012 Rule 21.1, required]
案例 2:
#ifndef __CCP_H__
#define __CCP_H__ //lint !e9071
#include "Ccppar.h"
#define MAJOR 0x02
#define MINOR 0x01
/* other parts of code */
#endif
观察到以下 Misra 警告:
defined macro '__CCP_H__' is reserved to the compiler [MISRA 2012 Rule 21.1, required]
C 标准,更不用说 MISRA,保留所有以双下划线开头的标记。
您 运行 的实际风险是您的 C 标准库实现使用该符号甚至编译器本身,这与您的冲突。
C11 §7.1.3 Reserved identifiers 的一部分说:
- 所有以下划线和大写字母或其他下划线开头的标识符始终保留供任何使用。
- 所有以下划线开头的标识符始终保留用作普通和标记名称空间中具有文件范围的标识符。
另见 What does double underscore (__const
) mean in C?