[previous] 3495 [next] Using a conditional operator in place of a selection statement.
Arithmetic type - Operations

This message is issued whenever the result of the conditional operator is not used, and it can be replaced with an equivalent if statement.

For example:


/*PRQA S 1-9999 ++*/
/*PRQA S 3491,3492,3495 --*/

#define SELECT(a, b, c) ((a) ? (b) : (c))

void f3495 (int a)
{
  SELECT (a > 0, --a, 0);   /* 3495, also 3491 */

  ((a > 0) ? --a : 0);      /* 3495, also 3492 */

  if (a > 0)
  {
    --a;
  }
  else
  {
    // no side effect
  }
}

See also:

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