[previous] 1895 [next] The 2nd and 3rd operands of this conditional operator are both 'essentially floating' ('%1s' and '%2s') but one is a composite expression of a narrower type than the other.
Arithmetic type - Composite expressions

This message is issued whenever a composite expression of essentially floating type has been used as the 2nd or 3rd operand of the conditional operator, and undergoes a usual arithmetic conversion to a wider floating type (the type of the other operand).

It is a common misconception among programmers that the type in which the narrower operand is evaluated is influenced by the wider type. Instead, the type of the expression is determined solely from the type of its operands. Therefore, a loss of precision, overflow or underflow may occur, which could be avoided if the operand was cast to the wider type.

For example:


/*PRQA S 1-9999 ++*/
/*PRQA S 1895 --*/

double f1895 (float a, double b)
{
  b = a > 0.0f ? (a - 1.0f) : b;       /* 1895 */

  return (a > 0.0f ? (a / 3.0f) : b);  /* 1895 */
}

For the purposes of QA·C conversion messages, types are ordered according to the configured size (-s option), by default; hence for a typical 32 bit configuration, types int and long will be considered equivalent. However, when the -strictrank option is specified, types will be ordered according to their rank; consequently int will be considered narrower than long.

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