[previous] 0735 [next] Using relational or logical operators in a 'switch' expression is usually a programming error.
Switch statements

This switch statement has a controlling expression which is effectively Boolean - i.e. it will evaluate to either 0 or 1. This is probably a mistake.

For example:


/*PRQA S 2017 ++*/

/*PRQA S 2002,2017,3227,3408,3447 ++*/

extern int x;

void foo(int option, int pick)
{
    switch (option == pick)          /* Message 0735 */
    {
    case 0:
        ++x;
        break;

    case 1:
        x = 0;
        break;
    }
}

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