[previous] 4115 [next] Operand of logical && or || operator is not an 'essentially Boolean' expression.
Arithmetic type - Operands REFERENCE - ISO:C90-6.3.13 Logical AND Operator, ISO:C90-6.3.14 Logical OR Operator

An operand of this logical && or logical || operator is not an effectively Boolean expression.

The ISO;C90 language does not support an explicitly Boolean type. Type _Bool was introduced in ISO:C99 but is not recognised in the current version of QA·C. In both versions of the language, there exist a number of operators which always yield a value of either 0 or 1 which is of type int. These operators are:

Although these operators yield a value of type int, the underlying type may be considered to be effectively.boolean.

The logical operators && and || not only yield a result of effectively Boolean type; they also interpret their operands in a Boolean sense by comparing them with 0. According to the ISO:C standard, these operands can be of any scalar type. However, message 4115 is generated whenever the underlying type of an operand is NOT effectively Boolean.

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

For example:


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

extern unsigned int ui;
extern unsigned int uj;

extern void foo(void)
{
    if ((ui != 0U) && (uj > 0U)) { }        /*              */
    if ((ui > 10U) || uj) { }               /* Message 4115 */
    return;
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents