14.3 and do-while within logical-and operator

Moderators: misra-c, david ward

Post Reply
lovewar
Posts: 10
Joined: Thu Feb 17, 2011 8:01 am
Company: .

14.3 and do-while within logical-and operator

Post by lovewar » Mon Jul 06, 2015 6:58 am

Would the following example be compliant with rule #14.3?

Code: Select all

 do {
     // code..
 } while ( (s8a < 10) && (s8a > 20) );  /* is && operator an essentially boolean controlling expression ? */ 
 

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

Re: 14.3 and do-while within logical-and operator

Post by misra-c » Wed Aug 05, 2015 8:57 am

The controlling expression of the while loop in the above example is "(s8a < 10) && (s8a > 20)". This expression will evaluate to False for all values of s8a. Therefore this is non-compliant with the rule 14.3.
---
Posted by and on behalf of
the MISRA C Working Group

lovewar
Posts: 10
Joined: Thu Feb 17, 2011 8:01 am
Company: .

Re: 14.3 and do-while within logical-and operator

Post by lovewar » Tue Aug 18, 2015 7:23 am

The controlling expression of the while loop in the above example is "(s8a < 10) && (s8a > 20)". This expression will evaluate to False for all values of s8a. Therefore this is non-compliant with the rule 14.3.
Isn't it target by exception 2 ?

Steve Montgomery
Posts: 104
Joined: Fri Sep 17, 2004 1:31 pm
Company: .
Location: Northumberland or Isle of Skye

Re: 14.3 and do-while within logical-and operator

Post by Steve Montgomery » Tue Aug 18, 2015 9:03 am

I agree - it's compliant by virtue of exception 2 isn't it? I can't see how it's any different from this example given under Rule 14.3:

Code: Select all

do {
  /* Compliant by exception 2 */
} while ( 0u == 1u );

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

Re: 14.3 and do-while within logical-and operator

Post by misra-c » Fri Sep 18, 2015 1:05 pm

The MISRA-C group apologise for the incorrect response first given to this question. The above posters are correct in saying the example meets the requirements of exception 2 and is therefore compliant with rule 14.3.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.14 Control statement expressions”