[previous] 4397 [next] An expression which is the result of a ~ or << operation has not been cast to its essential type.
Arithmetic type - Casts

This message is issued whenever a composite expression, which is the result of a ~ or << operation and is of essential type narrower than int, subsequently undergoes a usual arithmetic conversion.

The expression should first be cast to the same essential type, to ensure that there is no reliance on the effects of integral promotion. Specifically, higher order bits beyond these in the original essential type may get set, contrary to programmer's intention. These bits will be cleared by the cast.

For example:


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

unsigned f4397 (unsigned short a, unsigned b)
{
  b = (a << 1u) + b;        /* 4397 */

  return ((~a) + b);        /* 4397 */
}

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