The Meaning of Rule 12.6?

6.12 Expressions

Moderators: misra-c, david ward

Locked
Hammer
Posts: 9
Joined: Thu Mar 30, 2006 1:45 pm

The Meaning of Rule 12.6?

Post by Hammer » Thu Apr 06, 2006 8:30 am

I am trying to understand this rule and need someone to clarify its exact meaning.

which of the following are violations of Rule 12.6?

Code: Select all


 if((x==y)|(y==a))/*Violation?, could || have been meant?*/
   {    
 
   }
This is a violation of the old equivalent rule 36 but is it still a violation now?

Code: Select all


a=a+y+x+(x||y);
/*Violation, effectively boolean expression used with + operator*/

Code: Select all


int32_t x=5;
int32_t y=11;

if(x||y) /*Could this be a violation??? because x and y are not effectively boolean*/
   {
      
   }


Thanks for you help!

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

Post by misra-c » Thu Apr 27, 2006 11:05 am

Code: Select all

if ( ( x == y ) | ( y == a ) ) /*Violation?, could || have been meant?*/ 
   {    
  
   }

a = a + y + x + ( x || y );


These are violations of 12.6. as effectively boolean expressions are being used as the operand of an operator other than &&, || and !.

Code: Select all

int32_t x = 5; 
int32_t y = 11; 

if ( x || y ) /*Could this be a violation??? because x and y are not effectively boolean*/ 
   { 
      
   }


This is a violation of the first sentence of 12.6.
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.12 Expressions”