This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/46090] New: 16 bit uint16_t puts non-zero in highest bits when shifting


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46090

           Summary: 16 bit uint16_t puts non-zero in highest bits when
                    shifting
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kshakhna@gmail.com


This problem occurred on 64-bit Linux platform.

Here is an example of code for reproducing problem.

#include <stdint.h>

uint16_t In16(uint16_t input)
{
        uint16_t len = (input * 0x0101) >> 8;
        return len;
}


int len = In16(0x808);

When passing input=0x808, expected result:

1. len = (input * 0x0101) >> 8;
2. len = (0x808 * 0x0101) >> 8;
3. len = (0x808 + 0x0800) >> 8;
4. len = 0x1008 >> 8;
5. len = 0x10;

Instead of 0x10, result is 0x810
3. len = (0x808 + 0x80800) >> 8;
Here higher than 16 bit is not truncated.
4. len = 0x81008 >> 8;
5. len = 0x810;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]