[previous] 4131 [next] Left shift operation on signed operand.
Arithmetic type - Operations

A left shift operation is being performed on an operand whose underlying type is signed. The value of the result will be implementation-defined but probably meaningless.

Shift operations on signed data are not recommended. The internal representation of negative integer numbers is implementation defined (although usually two's complement), and it is seldom meaningful to manipulate signed data with shift operators.

A special situation arises when an expression of a small unsigned integer type is the left hand operand of a shift operator. Expressions of this type are subject to integral promotion and so although the underlying data is unsigned the result type will be signed int. QAC does not generate message 4131 when the underlying type of the operand is unsigned.

For example:


/*PRQA S 2017,2100,3120,3198,3408,3447 ++*/

extern int           sia;
extern unsigned char uca;

extern void foo(void)
{
    sia = sia << 3;        /* Message 4131 */
    sia = uca << 3;        /* No message */

    sia = sia >> 3;        /* Message 0502 */
    sia = uca >> 3;        /* No message   */
}


No MISRA-C:2004 Rules applicable to message 4131


See also:

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