我对此Misra警告有两个用例,如下所述。编译器是否为#if定义保留了某些名称或特定名称而不能使用?
目前,我已禁用此警告,//lint !e9071但是我们真的需要对此类警告采取任何措施吗?如果我们禁用此类警告,将会有任何影响或风险吗?
情况1:
#ifndef __CCPPAR_H__
#define __CCPPAR_H__ //lint !e9071
#include "Ccp_Cfg.h"
#endif /* multiple inclusion protection - __CCPPAR_H__ */
Run Code Online (Sandbox Code Playgroud)
观察到的警告:
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)
观察到以下Misra警告:
Run Code Online (Sandbox Code Playgroud)defined macro '__CCP_H__' is reserved to the compiler [MISRA 2012 Rule 21.1, required]
C标准(更不用说MISRA)保留以双下划线开头的所有令牌。
运行的实际风险是使用该符号或什至是编译器本身的C标准库实现,这与您的代码冲突。
部分C11§7.1.3保留标识符说: