[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:2004 Rules applicable to message 4397:

Rule  10.5  (Required) If the bitwise operators ~ and << are applied to an operand of underlying type unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operand.


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