[previous] 2920 [next] Constant: Left shift operation on expression of unsigned type results in loss of high order bits.
Shift operations

A left-shift operation is being performed on a constant expression of unsigned integer type and this will result in the loss of some non-zero high-order bits. Is this intended ?

For example:


/*PRQA S 1279,2017,2022,2982,2984,3120,3198,3211,3301,3408 ++*/

unsigned long ula;

extern void foo(void)
{
    ula = 0x00F00000UL << 8;            /*      */
    ula = 0x00F00000UL << 9;            /* 2920 */
    ula = 0x0F000000UL << 4;            /*      */
    ula = 0x0F000000UL << 5;            /* 2920 */
    ula = 0xF0000000UL << 0;            /*      */
    ula = 0xF0000000UL << 1;            /* 2920 */
}


No MISRA C:2012 Rules applicable to message 2920


See also:

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