[previous] 4114 [next] Operand of ~ operator is a 'Boolean' expression.
Arithmetic type - Operands REFERENCE - ISO:C90-6.3.3.3 Unary Arithmetic Operators

The operand of this bitwise complement operator (~) is an expression which is effectively Boolean. This is bad practice at best and probably a mistake.

Perhaps a logical negation operator (!) was intended ?

For example:


/*PRQA S 2017,3120,3198,3204,3227,3408 ++*/

int foo(int a, int b)
{
    int x;

    x = ~((a > b) && (b > 10));        /* Message 4114 */

    x = !((a > b) && (b > 10));        /*              */

    return x;
}


MISRA-C:2004 Rules applicable to message 4114:

Rule  12.6  (Advisory) The operands of logical operators (&&, || and !) should be effectively Boolean. Expressions that are effectively Boolean should not be used as operands to operators other than (&&, ||, !, =, ==, != and ?:).


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