Rule 12.6

6.12 Expressions

Moderators: misra-c, david ward

Post Reply
azukich
Posts: 2
Joined: Fri Feb 13, 2009 2:25 pm
Company: Klocwork

Rule 12.6

Post by azukich » Wed Oct 27, 2010 4:55 pm

Klocwork has been getting a number of complaints on our interpretation of rule 12.6. For example:

If(TRUE==TRUE) ...

So if TRUE is a Boolean. “==” is not of &&, ||, !. We report this as a violation, since the code should look like
If(TRUE) ...

Many people have debated this. Are we misunderstanding this?

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

Re: Rule 12.6

Post by misra-c » Wed Nov 03, 2010 8:51 am

This rule was clarified in technical corrigendum (TC1) and the wording is now:
The operands of logical operators (&&, || and !) should be effectively Boolean. Expressions that are effectively Boolean should not be used as operands to operators other than (&&, ||, !, =, ==, != and ?:)
According to this wording, your example:

Code: Select all

if (TRUE==TRUE)
is not a violation of Rule 12.6.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.12 Expressions”