[previous] 1410 [next] Enum object is being compared with a constant, non-enum expression using an equality operator.
Arithmetic type - Enum types REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers

An enum object is being compared with the value of a constant expression using an equality operator. If the value of the constant expression is the same as one of the enum constants, wouldn't it be better to use the symbolic enum constant instead ? If it isn't, the operation is redundant and is probably a mistake.

For example:


/*PRQA S 1-9999 ++*/
/*PRQA S 1410, 1317, 1414, 1475, 1476 --*/

enum SIZE   { SMALL = 2, MEDIUM = 4, LARGE = 6 };

extern void foo(enum SIZE box)
{
   if (box == LARGE ) { }       /*                     */
   if (box == 4  ) { }          /* Message 1410        */
   if (box != (2 + 3) ) { }     /* Message 1410 + 1317 */


   if (box <= MEDIUM ) { }      /*                     */
   if (box >  2  ) { }          /* Message 1414        */
   if (box < (4 + 3) ) { }      /* Message 1414 + 1475 */
   if (box <  2  ) { }          /* Message 1414 + 1476 */
}

See also:

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