[previous] 3344 [next] Controlling expression is not an 'essentially Boolean' expression.
Control flow

Controlling expressions appear in if, for, while or do ... while constructs and as the first operand of a conditional operator. They are expressions which always undergo an implicit test against the value '0'. However they are most readable when formed from an operator which explicitly yields a result of 0 or 1.

Message 3344 is generated when a controlling expression is not formed from one of the following operators:

So, for example, rather than using an integer variable, e.g. "x", as a controlling expression, it may be preferable to use the expression "x != 0", so that the logical comparison is made explicit.

For example:


/*PRQA S 2017,2213,3198,3199,3203,3408,3447 ++*/

extern int a;
extern int b;

extern void foo(void)
{
    int r;

    if (a) { }                  /* Message 3344 */
    while (a + b) { --a; }      /* Message 3344 */
    r = a ? a : b;              /* Message 3344 */

    if (a != 0) { }             /* OK */
    while (a > b) { ++b; }      /* OK */
    r = (a < b) ? a : b;        /* OK */
}


MISRA C:2012 Rules applicable to message 3344:

Rule-14.4  (Required) The controlling expression of an if-statement and the controlling expression of an iteration-statement shall have essentially Boolean type


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents