简体   繁体   中英

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. Does compiler reserve some or specific name for #if defines which can't be used?

Currently, I have disabled this warning by //lint !e9071 but do we really need to do anything for such warnings? Is there any impact or risk if we disabled such warnings?

Case 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:

#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:

 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.

The practical risk you run is your C standard library implementation using that symbol or even the compiler itself, which clashes with yours.

Part of C11 §7.1.3 Reserved identifiers says:

  • 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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