[previous] MISRA C:2012  Rule-14.4:  (Required) [next] The controlling expression of an if-statement and the controlling expression of an iteration-statement shall have essentially Boolean type

Amplification:

The controlling expression of a for-statement is optional. The rule does not require the expression to be present but does require it to have essentially Boolean type if it is present.

Example Code:


#include "misra.h"
#include "m3cmex.h"

extern int16_t rule_1404( void )
{
   uint16_t ux;
   uint16_t uy;

   ux = get_u16();
   if ( ux )                            /* 3344      */
   {
   }

   ux = get_u16();
   while (ux)                           /* 3344      */
   {
       --ux;
   }

   ux = get_u16();
   do
   {
       --ux;
   } while (ux);                        /* 3344      */


   for (ux = 10; ux; --ux)              /* 3344      */
   {
   }

   ux = get_u16();
   s16c = ux ? s16a : s16b;             /* 3344 4559 */


   return s16r;
}


QAC messages that encompass this guideline:

3344 Controlling expression is not an 'essentially Boolean' expression.



(c) The Motor Industry Research Association, 2012
QA C Source Code Analyser 8.1.2
MISRA C:2012 Compliance Module 1.0
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents