Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

misra

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]
like image 900
kapilddit Avatar asked Mar 04 '23 13:03

kapilddit


1 Answers

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?

like image 160
2 revs, 2 users 64% Avatar answered Apr 29 '23 20:04

2 revs, 2 users 64%