Rule 12.6, effectively Boolean expressions in assignment?

6.12 Expressions

Moderators: misra-c, david ward

Locked
rmgalles
Posts: 7
Joined: Fri Jan 20, 2006 3:45 pm
Location: USA

Rule 12.6, effectively Boolean expressions in assignment?

Post by rmgalles » Fri Feb 03, 2006 9:29 pm

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: Select all

bool a;

a = (b == c); /* is this allowed? */
Perhaps a disclaimer \"other than assignment\" could be added?

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

Post by misra-c » Thu Apr 27, 2006 10:56 am

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

Code: Select all

a = (b == c);  
a = b > 5;
c = a || b;
These are allowed

Full clarification will be in Technical Clarification 1.
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.12 Expressions”