MISRA Discussion Forums
14.3 and do-while within logical-and operator - 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:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.14 Control statement expressions (https://forum.misra.org.uk/forumdisplay.php?fid=169)
+---- Thread: 14.3 and do-while within logical-and operator (/showthread.php?tid=1193)



14.3 and do-while within logical-and operator - lovewar - 06-07-2015

Would the following example be compliant with rule #14.3?
Code:
do {
     // code..
} while ( (s8a < 10) && (s8a > 20) );  /* is && operator an essentially boolean controlling expression ? */



Re: 14.3 and do-while within logical-and operator - misra-c - 05-08-2015

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.


Re: 14.3 and do-while within logical-and operator - lovewar - 18-08-2015

Quote: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 ?


Re: 14.3 and do-while within logical-and operator - Steve Montgomery - 18-08-2015

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:
do {
  /* Compliant by exception 2 */
} while ( 0u == 1u );



Re: 14.3 and do-while within logical-and operator - misra-c - 18-09-2015

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.