Rule 5.4: Macro identifier

Moderators: misra-c, david ward

Post Reply
Polyspacer
Posts: 2
Joined: Thu Aug 21, 2014 6:27 am
Company: Daimler AG

Rule 5.4: Macro identifier

Post by Polyspacer » Tue Jun 16, 2015 1:01 pm

I have a question regarding rule 5.4: Which of the following #defines is violating this rule?

Code: Select all

#define  engine_exhaust_gas_temperature_high_raw     egt_r
#define  engine_exhaust_gas_temperature_high_scaled  egt_s 

#define x 0
#define x 0

#ifndef ABCDE
#define DAI_AGK_SEC_1BIT_RAM_START
#endif

#ifndef FGHIJ
#define DAI_AGK_SEC_1BIT_RAM_START
#endif

unsigned long int A; 
unsigned short int Con = 0;

void main(void) 
{

	/*5.4*/
	#ifdef DAI_AGK_SEC_1BIT_RAM_START
	A = Con;
	#endif
	A = x;
	
}
The 1st and 2nd #define are similar to the example given in the MISRA-C guideline. Hence, the 2nd #define violates the rule.
The 3rd and 4th #define are identical. Therefore, the 4th #define violates the rule.
The 5th and 6th #define are identical as well. Does the 6th #define violate the rule? According to the glossary, the macro name is a macro identifier...

misra-c
Posts: 560
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 5.4: Macro identifier

Post by misra-c » Thu Jun 25, 2015 9:04 am

The amplification states
This rule requires that, when a macro is being defined, its name be distinct from:
  • the names of the other macros that are currently defined;
Therefore there will only be a violation of Rule 5.4 on DAI_AGK_SEC_1BIT_RAM_START if both ABCDE and FGHIJ are not defined.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.5 Identifers”