[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 */
}


MISRA C:2012 Rules applicable to message 4397:

Rule-10.7  (Required) If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential type


QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents