[previous] 1894 [next] The 2nd and 3rd operands of this conditional operator are both 'essentially unsigned' ('%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 unsigned type has been used as the 2nd or 3rd operand of the conditional operator, and undergoes a usual arithmetic conversion to a wider unsigned integer 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 after any integral promotion. Therefore, wraparound may occur, which could be avoided if the operand was cast to the wider type.

For example:


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

unsigned f1894 (unsigned short a, unsigned b)
{
  b = (a > 0) ? (a + 1) : b;       /* 1894 */

  return ((a > 0) ? (a * 2) : b);  /* 1894 */
}

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