MISRA Discussion Forums
Rule 12.6, effectively Boolean expressions in assignment? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.12 Expressions (https://forum.misra.org.uk/forumdisplay.php?fid=39)
+---- Thread: Rule 12.6, effectively Boolean expressions in assignment? (/showthread.php?tid=208)



Rule 12.6, effectively Boolean expressions in assignment? - rmgalles - 03-02-2006

The second sentence in Rule 12.6 says \"Expressions that are effectively Boolean should not be used as operands to operators other than (&&, || and !).\"

This makes sense for most operators, but what about the simple assignment operator?

Code:
bool a;

a = (b == c); /* is this allowed? */

Perhaps a disclaimer \"other than assignment\" could be added?


- misra-c - 27-04-2006

An effectively boolean expression can be the operand of the assignment operator or any operand of the ternary operator.

Code:
a = (b == c);  
a = b > 5;
c = a || b;

These are allowed

Full clarification will be in Technical Clarification 1.